Copy variables from RITM to SCtask

dharam743
Tera Contributor

I want to copy variables from an RITM (Request Item) to an SCTask (Service Catalog Task) when the SCTask is created using the "New" button in the related list on the RITM form, how to achieve this?

 

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@dharam743 

why would someone create catalog task via New button?

They are meant to be created as part of flow or workflow

But if you still require then check this link

Adding Variables to a Task via a script instead of using the slush bucket within a workflow for a C... 

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

View solution in original post

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @dharam743 

 

you can use the BR for same , I am good in code but this what i can suggest. You need to modify the OOTB new button and the via get and set value you an set the values. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Ankur Bawiskar
Tera Patron
Tera Patron

@dharam743 

why would someone create catalog task via New button?

They are meant to be created as part of flow or workflow

But if you still require then check this link

Adding Variables to a Task via a script instead of using the slush bucket within a workflow for a C... 

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

Thanks @Ankur Bawiskar 

 

You're right that the catalog task should ideally be created using a flow or workflow. However, for one specific scenario, I wanted to handle it differently.

I used the same script in a Before Insert Business Rule, and it's working as expected.

 

(function executeRule(current, previous /*null when async*/ ) {

    var vars = new GlideRecord("item_option_new");
    vars.addQuery('cat_item', current.request_item.cat_item);
    vars.query();

    while (vars.next()) {
        insertVariable(vars.sys_id);
    }

    function insertVariable(id) {
        var gr = new GlideRecord('sc_item_variables_task');
        gr.initialize();
        gr.setValue('task', current.getValue('sys_id'));
        gr.setValue('variable', id);
        gr.insert();
    }

})(current, previous);

 
@Michael Jones - Thanks you too, you explained it very well. 🙂