The CreatorCon Call for Content is officially open! Get started here.

Populating the RITM Category with Catalog task category.

kirthi1
Tera Contributor

Populating the RITM Category with Catalog task category.

I am looking to see if there is a possibility to populate the Category on the RITM with the Category on the Catalog task.

These are 2 independent fields and we did not have the requirements initially to have category on the RITM level and now the Category on RITM is important requirement.

Any help is appreciated. 

 

8 REPLIES 8

Swadesh Saraf2
Kilo Guru

Yes you can do this. 

 

I am simply eyeballing the script here:

 

var grItem = new GlideRecord('sc_req_item');

grItem.addQuery('sys_id',current.parent);

grItem.setLimit(1);

grItem.query();

if(grItem.next())

{

grItem.u_category = current.u_category;

grItem.update();

}

The above script will work for any newly created record when put in business rule.

If you need to update old records:

var grTask = new GlideRecord('sc_task');

grTask.addNotNullQuery('u_category);

grTask.query();

while(grTask.next())

{

var grItem = new GlideRecord('sc_req_item');

grItem.addQuery('sys_id',grTask.parent);

grItem.setLimit(1);

grItem.query();

if(grItem.next())

{

grItem.u_category = grTask.u_category;

grItem.update();

}

}

 

Please verify the script once before running for all the records.

 

Vanashree Kubal
Kilo Guru

Hi Kirthi,

Please refer below link, from that you can understand the proper solution.

you can use this for your examination also.

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

 

If you think that my answer help you to solved issue please marked correct or helpful

Vanashree Kubal

Mohit Kaushik
Mega Sage
Mega Sage

Hi Kirthi,

 

You can create an after Insert business rule on catalog task. Where you will populate the category for RITM until it is empty. Suppose there are multiple ctask on the RITM then it should not overwrite the category again and agian.

Script will be:

var item = new GlideRecord('sc_req_item');

item.addQuery('sys_id',current.<backend value of request item field>);

item.addQuery('u_category',''); //enter in the loop only if category is empty

item.query();

if(item.next())

{

item.u_category=current.u_category

item.update();

}

 

 

Please mark my answer correct and helpful if it resolved the query and only helpful if it helped you at all.

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

kirthi1
Tera Contributor

I tried the above 2 scripts and for some reason it did not update the Requested Items Category when I changed the Catalog item category.

Could you please let me know what am I doing wrong.

When I change the Catalog item category the Requested Item Category needs to be updated.

find_real_file.png

find_real_file.png

find_real_file.png