Set RITM to Work in Progress

Rocky5
Kilo Sage

Hello Experts,

I wanted to set RITM state to "Work in Progress" when any catalog task state of that RITM is set to "Work in progress", I have written the below script "after" update BR on Sc_Task table, It works as expected but some Random blank RITMs are getting created. Assuming that is because sc_task doesn't have request_item as soon as gr.update(); happens on the empty gliderecord it is inserting the new record.

Is my assumption correct? if so, what is other alternative to achive this requirement.

After update BR on sc_task table:

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

    var gr = new GlideRecord('sc_req_item');
    gr.get(current.getValue('request_item'));
    gr.state = 2;
    gr.update();

})(current, previous);

Thanks,

Rocky.

 

6 REPLIES 6

Mohith Devatte
Tera Sage
Tera Sage

hello,

Can you please check if there is any other after update BR on RITM table which might have been configured to insert RITM through gr.initialize()  and gr.insert() code  on some conditions  like state changes to WIP which is getting satisfied while you update it through your BR

 

also try adding two add queries 

 gr.addQuery('active', true);
 gr.addQuery('request_item',current.sys_id); 

because you are just updating the ritm in your script but you did not mention which RITM . So if you try adding these two lines you will be updating the RITM which is tagged to your catalog task

 

please mark this helpful if you find it useful.

Thanks,

Mohith Devatte.

Hi Mohith,

I see no other BR's that inserts RITM records.

Thanks,

Rocky.

Hello,

Can you please try this below script

 

var gr = new GlideRecord('sc_req_item');

 gr.addQuery('sys_id',current.request_item);// replace request_item with the backend name of field "Requested item" on catalog task form according to your instance .If is same plese leave it as is.

gr.query();

if(gr.next())

{

gr.state = 2;
    gr.update();

}

Please mark this helpful if this solves your issue.

Thanks,

Mohith

Palak Gupta
Tera Guru
Tera Guru

Hi there!

Change your script as below and try again

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

    var gr = new GlideRecord('sc_req_item');

 gr.addQuery('active', true);
 gr.addQuery('request_item',current.sys_id); 

    gr.state = 2;
    gr.update();

})(current, previous);

Regards,

Palak