How to query the item in stored in array?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 09:39 AM
Hi All,
I had a requirement to include the item which comes from the system properties and add those whether it is active true or false.
I have created a if condition workflow script to check the item with the catalog item that comes from the properties.
answer = ifScript();
function ifScript()
{
var a=current.sys_id;
var flag = false;
var prop = gs.getProperty('test_sys_prop_catitem');
var prop1 = prop.split(',');
var gr_sc_item = new GlideRecord("sc_req_item");
gr_sc_item.addQuery("request",a);
gr_sc_item.query();
if(gr_sc_item.next())
{
var catitem=gr_sc_item.cat_item;
}
for(var i =0;i<prop1.length;i++){
if(catitem == prop1[i]){
flag = true;
}
}
if (flag == true)
{
workflow.scratchpad.group = 'a4387fhfjh4584793fddfj495848fj4'; //test group 1
return 'yes';
}
else
{
workflow.scratchpad.group = '3874efhdjfhjkgnfvjkyh4u54ifh4i4f4'; //test group 2 support
return 'no';
}
}
"test_sys_prop_catitem" this is the system property which has the sysid 's of catalog item
Here from this part ,I am checking the property item stored in array with the catlog item but I need to do dot walking in array to take the item active is true or false.
for(var i =0;i<prop1.length;i++){
if(catitem == prop1[i]){
flag = true;
}
Anyone have any idea how to do that.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 09:56 AM
You can do some improvements to your script. for loop should be inside if and you can also use indexOf() to find the sysid
answer = ifScript();
function ifScript()
{
var a=current.sys_id;
var flag = false;
var prop = gs.getProperty('test_sys_prop_catitem');
var prop1 = prop.split(',');
var gr_sc_item = new GlideRecord("sc_req_item");
gr_sc_item.addQuery("request",a);
gr_sc_item.query();
if(gr_sc_item.next())
{
var catitem=gr_sc_item.getValue('cat_item');
if (prop1.indexOf(catitem)>-1)
flag= true;
}
if (flag == true)
{
workflow.scratchpad.group = 'a4387fhfjh4584793fddfj495848fj4'; //test group 1
return 'yes';
}
else
{
workflow.scratchpad.group = '3874efhdjfhjkgnfvjkyh4u54ifh4i4f4'; //test group 2 support
return 'no';
}
}
Please mark this response as correct or helpful if it assisted you with your question.