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

@BanuMahalakshmi 

Hope you are doing good.

Did my reply answer your question?

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

Medi C
Giga Sage

Hi @BanuMahalakshmi ,

It looks like the site value is empty. Please ensure that the value is not empty before splitting. Here is a script you can try:

 

var assignmentgroup;
var site = fd_data.trigger.request_item.variables.site;

var keyword = "";
var query = 'u_group_user=Group^u_contact_type=Local Support';

if(site){
   keyword = site.split("-")[0].trim();
   query += keyword+"" == "" ? "" : "^u_location=" + keyword;
}

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(query);
    assignmentgroup_val.query();
    assignmentgroup_val.setLimit(1);
    if (assignmentgroup_val.next()) {
        assignmentgroup = assignmentgroup_val.u_group;
      }
      else
      {
         assignmentgroup = '0e1285371b58c450c9307510cd4bcbed';
      }
    return assignmentgroup;
}

If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.