can not read the property 0 from undefined into flow design

BanuMahalakshmi
Tera Contributor

Hi 

I am getting the error message "cannot read the property 0 from undefined" while assign value into flow design task assignment group stage. please let me know correction in the script:

var assignmentgroup;
var site = fd_data.trigger.request_item.variables.site;
var keyword= site.split("-")[0].trim();

var siteval = gs.getProperty('locations.with.network.lan.resource').split(',');
var index = -1;
index = siteval.indexOf(keyword);

if(index > -1)
{
 assignmentgroup = '0e1285371b58c450c9307510cd4bcbed';
}
else
{
    var assignmentgroup_val = new GlideRecord('u_location_point_of_contact');
    assignmentgroup_val.addQuery('u_group_user=Group^u_contact_type=Local Support');
    assignmentgroup_val.addQuery('u_location', '=', site);
    assignmentgroup_val.query();
    assignmentgroup_val.setLimit(1);
    if (assignmentgroup_val.next()) {
        assignmentgroup = assignmentgroup_val.u_group;
            }
    else
    {
                assignmentgroup = '0e1285371b58c450c9307510cd4bcbed';
    }
return assignmentgroup;
}

 

 

BanuMahalakshmi_0-1741702690828.png

 

6 REPLIES 6

J Siva
Tera Sage

Hi @BanuMahalakshmi 

As I mentioned in the previous thread, use Get catalog variable action instead of using request_item.variables.

Then, lookup group record by passing the sys_id and finally use the assignment group record obj in the create catalog task action.

 

Regards,

Siva

priyatam_pvp
Tera Guru

The error ā€œCannot read property ā€˜0’ from undefinedā€ typically occurs because the script tries to access an index (0) of an undefined or null value. In your case, this happens while executing:

var keyword= site.split("-")[0].trim();

Before using .split("-"), ensure the site is defined and not empty.

Please mark it helpful
Priyatam Patchipulusu

Shivalika
Mega Sage

Hello @BanuMahalakshmi 

 

It's happening. Because your site is not having any value and you are trying to read (0) index from it. 

 

Please create additional step in flow designer to get Catalog variables and then reference that flow step to access the value of site and also convert it to string to or access name directly to traverse 0 index. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway,

 

Regards,

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwN

eEISQCY

Ankur Bawiskar
Tera Patron
Tera Patron

@BanuMahalakshmi 

it's because of these lines

var site = fd_data.trigger.request_item.variables.site;
var keyword= site.split("-")[0].trim();

Take this approach

1) use Get Catalog Variables flow action

2) then use IF flog logic to see if that variable is not empty

3) then within that IF have create catalog task with that script and access the variable value like this

Get Catalog Variable->VariableName

OR

1) Create a flow variable of type string

2) use Get Catalog Variables flow action

3) then use Set Flow Variable logic and use script to determine the group and return the sysId and store in flow variable

4) then use that flow variable during your catalog task creation while assigning

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader