Unable to update requested_for field in sc_task Form, where sysid of user stored in variable/

VIKASM535239375
Kilo Sage

Unable to update requested_for field in sc_task Form, where sysid of user stored in variable.

 

Please find the script below . Please let me know what is to be corrected.

 

var reqsfor = Email;
    var userGr = new GlideRecord('sys_user');
    userGr.addQuery('email', reqsfor);
    userGr.query();

    var userSysId = null;
    if (userGr.next()) {
        userSysId = userGr.getUniqueValue();
        gs.info("Test Florida" + userSysId);
    } else {
        gs.error('User not found: ' + reqsfor);
        return;
    }
 
var ritm = new GlideRecord('sc_task');
    ritm.addQuery("u_vendor_order_number", Reqbodydata.Id);
 
    ritm.query();
    if (ritm.next()) {
        ritm.requested_for = userSysId;
ritm.update();}
 }
1 ACCEPTED SOLUTION

VIKASM535239375
Kilo Sage

Was  able to update requested_for field in sc_task Form using Request and Requested Item.

View solution in original post

4 REPLIES 4

RV MG
Tera Contributor

What script is it? you can directly use the requested_for variable type to populate the requested for. OOB there should already be a business rule that should do it. If you want to use some kind of custom logic, you will have to use the variable pool to access the email, and then make the query work

Scripted rest api post method script

Ankur Bawiskar
Tera Patron
Tera Patron

@VIKASM535239375 

Would you mind closing your earlier questions by marking appropriate response as correct?

Members have invested their time and efforts in helping you.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

VIKASM535239375
Kilo Sage

Was  able to update requested_for field in sc_task Form using Request and Requested Item.