creating RITM using inbound action and cart api

Rahul Raja Sami
Tera Guru

 

Hi 

 

Trying to create RITM using inbound action and below cart API

target table: sc_req_item


createRequest();
function createRequest() {
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
//give sys_id of catalog item
var item = cart.addItem('0498ad2987472450d0d4ca27cebb35cc', 1);
cart.setVariable(item,"requested_for", gs.getUserID());
cart.setVariable(item,'short_description',email.subject);
cart.setVariable(item,'please_select_the_request','Active Directory');
var rc = cart.placeOrder();
var tsk = new GlideRecord('sc_task');
tsk.addQuery('request', rc.sys_id);
tsk.query();
while (tsk.next()) {

tsk.assignment_group = 'd625dccec0a8016700a222a0f7900d06' ;// add your value
tsk.short_description = email.subject;
tsk.description = email.body_text;

tsk.u_sub_category = 'Active Directory'; //add your value

}
}

 

but after using this the sys email table target record is getting updated and this error showing on the log

 

RahulRajaSami_3-1669135032798.png

 

error

RahulRajaSami_2-1669134901383.png

 

and 2 RITM's are getting created

RahulRajaSami_1-1669134874407.png

 

why this is happening?

 

1 ACCEPTED SOLUTION

I have configured Inbound action for Task table and everything works fine.

View solution in original post

19 REPLIES 19

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Rahul Raja Sami ,

Your code works perfectly for me. Can you please check on your instance is there any kind of before Insert BR on sc_req_item table which is causing this empty ritm.


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Hi @Gunjan Kiratkar 

i am facing new issue now

when I sending a mail 

it is creating Req and RITM but RITM's creating by missing one 

for example

 

RahulRajaSami_0-1669136550298.png

 

but request numbers are creating correctly.

 

RahulRajaSami_0-1669136652460.png

 

why?

 

Hi @Rahul Raja Sami ,

To debug the issue and to check which scripts are running at backend, Better to use script debugger- script tracer and then perform task and see which scripts are running at that time and causing this issue.


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Hi Gunjan

 I have updated my script

 

var cart = new sn_sc.CartJS();
var request =
{
'sysparm_id': '0498ad2987472450d0d4ca27cebb35cc',
'sysparm_quantity': '1',
'variables':{
'description': email.body_text,
'short_description': email.subject,
'please_select_the_request':'Active Directory'
}
};
var rc = cart.orderNow(request);


sys_email.instance = rc.request_id;
sys_email.target_table = "sc_request";

 

this populates the target on sys_email but it didn't solve the missing RITM issue.

error in log : did not create or update sc_req_item using current