Tasks do not have the RITM already prefilled

Servicenow de11
Tera Contributor

Hello,

Sourcing tasks do not have the RITM already prefilled. Because of this we, need to open the REQ and see what the RITM number is, copy it, go back to the task and paste it just to source an item. Attached screenshot
Note: The task is to created based on Request table workflow not RITM Workflow. so RITM number is not auto populated.

Can anyone suggest me the script to autopopulate the RITM Number in Task record

Thanks in advance

 

1 ACCEPTED SOLUTION

Ok .

Create after insert BR on sc_task and add following script in it:

 

var getRITM = new GlideRecord('sc_req_item');
getRITM.addQuery('request',current.request);
getRITM.query();
if(getRITM.next()){
current.request_item = getRITM.sys_id;
current.update();
}

 

and then test !

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

View solution in original post

14 REPLIES 14

Ok .

Create after insert BR on sc_task and add following script in it:

 

var getRITM = new GlideRecord('sc_req_item');
getRITM.addQuery('request',current.request);
getRITM.query();
if(getRITM.next()){
current.request_item = getRITM.sys_id;
current.update();
}

 

and then test !

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

I have tested it but no luck still not getting populated

 

Does not make sense!

when task is created do you see RITM and task has same request numbers or its different request number?

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

FYI - I have a feeling the issue here is that the RITM Is not creating the task in question...hence my inquiry above...and why your suggested script is not working.

I think this is what is happening:

REQ is created ---> REQ workflow creates task (no RITM yet) ---> TASK exists ---> fulfiller activities based on business logic outside of S-Now (TASK is in progress) ---> *unknown trigger* (likely from TASK, but unknown to me at this point - related to approvals too?) ---> RITM is created ---> New Task(s) created via RITM (irrelevant to this problem) ---> initial task which is/was created by REQ is missing info about the RITM which was created....and here we are.

They need to have the workflow update the TASK it initially created with the new RITM number that was generated after the TASK in question was.

In order to help @Servicenow de11 we need to know the trigger that creates the RITM, because I don't think it's the creation of the REQ. They mention this in one of their replies:


@Servicenow_de11 wrote:

 

I cant shift the workflow to sc_req_item table because we have another workflow for RITM Table.

 

RITM approval is approved after that request table workflow task will trigger based on two conditions:

If the request is sourceable  and approval is approved

If this two conditions matches that request table workflow task will trigger

 


This sounds like there are multiple workflows calling each other.

My guess is that they need a BR which looks for the RITM and then glides to the REQ to find the TASK and then update THAT record...the BR can't trigger on the TASK because it seems to me that the RITM doesn't exist yet, so there would be no info there.

This theory is further supported by OP's screenshot (the record has a "TASK" prefix, not an "SCTASK" prefix)...I'm confident the task in question is not created by the RITM, which is why your suggested code is not working for them.

I have given one condition in that business rule. After that it was working fine. Thanks for the script