Copy the cat_item from the sc_req_item to the sc_task

Samuel Moya cam
Kilo Sage

Hi i am trying to get the cat_item from the sc_req_item and trying to copy it to the sc_task to add a condition to an acl.
This is what i got
1- This script gives me all the cat_item names but not the current cat_item from the sc_req_item

var target = new GlideRecord('sc_req_item');


target.addQuery('active', true);


target.query();  

while (target.next()) {  


                      gs.log("Item Name-"+target.cat_item.name);


}

2- This gives me an undefined value

var rec = new GlideRecord('sc_req_item');


rec.addQuery(current.cat_item);


rec.query();


gs.log(current.cat_item );

 

 

Thank you

1 ACCEPTED SOLUTION

Thanks. In your existing script replace

target.cat_item.name 

with

current.request_item.cat_item.name

View solution in original post

9 REPLIES 9

Community Alums
Not applicable

Hi @Samuel Moya campos ,

You can refer to this thread which you can use:

https://community.servicenow.com/community?id=community_question&sys_id=f4b232a7dbd4cd10847d5ac2ca96...

Mark my answer correct & Helpful, if Applicable.

Thanks,
Sandeep

Jaspal Singh
Mega Patron
Mega Patron

Hi Samuel,

Where are you using above scripts?

Hi. it´s an ACL i am using this scripts just before adding the condition, i show all the script to give some context.

var target = new GlideRecord('sc_req_item');


target.addQuery('active', true);


target.query();  

while (target.next()) {  


                      gs.log("Item Name-"+target.cat_item.name);


}
var rec = new GlideRecord('sc_req_item');
rec.addQuery(current.cat_item);
rec.query();
gs.log(current.cat_item );
var answer = false; //Restrict access by default

if(gs.hasRole('itil') && target.cat_item.name == 'Technical request'){
    gs.log("here");
    
   answer = true; 
}

Thanks. In your existing script replace

target.cat_item.name 

with

current.request_item.cat_item.name