antonanton
antonanton

Reputation: 591

Zoho Creator making a custom function for a report

Trying to wrap my head around zoho creator, its not as simple as they make it out to be for building apps… I have an inventory database, and i have four fields that I call to fill a field called Inventory Number (Inv_Num1) –

First Name (First_Name)

Last Name (Last_Name)

Year (Year)

Number (Number)

I have a Custom Function script that I call through a Custom Action in the form report. What I am trying to do is upload a CSV file with 900 entries. Of course, not all of those have those values (first/last/number) so I need to bulk edit all of them. However when I do the bulk edit, the Inv_Num1 field is not updated with the new values. I use the custom action to populate the Inv_Num1 field with the values of the other 4 fields.

Heres is my script:

void onetime.UpdateInv()
{
    for each Inventory_Record in Management
    {
        FN = Inventory_Record.First_Name.subString(0,1);
        LN = Inventory_Record.Last_Name.subString(0,1);
        YR = Inventory_Record.Year.subString(2,4);
        NO = Inventory_Record.Number;
        outputstr = FN + LN + YR + NO;
        Inventory_Record.Inv_Num1 = outputstr;
    }
}

I get this error back when I try to run this function

Error.
    Error in executing UpdateInv workflow.
        Error in executing For Each Record task.
            Error in executing Set Variable task. Unable to update template variable FN.
                Error evaluating STRING expression :

Even though there is a First Name for example, it still thinks there is none. This only happens on the fields I changed with Bulk Edit. If I do each one by hand, then the custom action works—but of course then the Inv_Num1 is already updated through my edit on success functions and makes the whole thing moot.

Upvotes: 1

Views: 2225

Answers (2)

jayesh sonawane
jayesh sonawane

Reputation: 11

this may be one year late, you might have found the solution but just to highlight, the error u were facing was just due to the null value in first name.

you just have put a null check on each field and u r good to go.

you can generate the inv_number on the time of bulk uploading also by adding null check in the same code on and placing the code on Add> On Submt.( just the part inside the loop )

the Better option would be using a formula field, you just have to put this formula in that formula field and you'll get your inventory_number autogenerated , you can rename the formula_field to Inv Number or whaterver u want.

Since you are using substring directly in year Field, I am assuming the year field as string.else you would have to user Year.tostring().substring(2,4) & instead of if(Year=="","",...) you have to put if(Year==null , null,...);

so here's the formula

    if(First_Name=="","",First_Name.subString(0,1))+if(Last_Name =="","",Last_Name.subString(0,1)) + if(Year=="","",Year.subString(2,4)+Number

Let me know ur response if u implement this.

Upvotes: 1

Ed Rochford
Ed Rochford

Reputation: 1

Without knowing the datatype its difficult to fix, but making the assumption that your Inventory_Record.number is a numeric data item you are adding a string to a number:

The "+" is used for string Concatenation - Joiner but it also adds two numbers together so think "a" + "b" = "ab" for strings but for numbers 1 + 2 = 3.

All good, but when you do "a" + 2 the system doesn't know whether to add or concatenate so gives an error.

Upvotes: 0

Related Questions