Scheduled entity generation, REQ fields not populating

nupur_goswami
Tera Contributor

I have created a catalog item that I want to automate the trigger of that catalog item every 3 months. I used scheduled entity generation to automate this and wrote a script to create an REQ and RITM for the same. But the values in REQ like requested for, short description and description are not populating when I execute it using the execute now button present at the bottom left corner. I have the same fields (requested for, short description and description) present on the catalog item as well. I tried to Glide Record as well but values on REQ number generated does not populate. Find the screenshot below for the code.

 

1 ACCEPTED SOLUTION

@nupur_goswami 

use this

orderNow function returns JSON object so updated the code to send the REQ sysId so that updateRITM function can query it correctly

// var answer = false;
// var date = new GlideDateTime();
// var month = date.getMonth();
// var day = date.getDayOfMonth();
// if (month == 1 || month == 4 || month == 7 || month == 10)  


// Create a new catalog request
createRequest();

function createRequest() {
    var cart = new sn_sc.CartJS();
    var request = {
        'sysparm_id': '354c9968fbec269033c5ff57aeefdccb', // sys ID of catalog item SAP EFS Approval Hierarchy Review Data Upload
        'sysparm_quantity': '1',
        'variables': {
            'requested_for': '8e4d9138dbe1cb042686da94ce961924', //sys ID of Louise Gulliford 
            'short_description': 'Create SAP EFS Approval Hierarchy Review Data Upload',
            'description': 'Create SAP EFS Approval Hierarchy Review Data Upload',
        }
    };

    var cartDetails = cart.orderNow(request);
    updateRITM(cartDetails.request_id);

}

function updateRITM(reqSysId) {

    var ritm = new GlideRecord('sc_req_item');
    ritm.addQuery('request', reqSysId);
    ritm.query();
    if (ritm.next()) {
        ritm.requested_for = '8e4d9138dbe1cb042686da94ce961924';
        ritm.short_description = "Create SAP EFS Approval Hierarchy Review Data Upload ";
        ritm.update();

        // update Requested for on REQ as well
        var req = ritm.request.getRefRecord();
        req.requested_for = '8e4d9138dbe1cb042686da94ce961924';
        req.update();

    }




}

{
    answer = true;
}
answer;

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

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@nupur_goswami 

share the script here and not the screenshots.

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

@Ankur Bawiskar 
Sharing the script here 

// var answer = false;
// var date = new GlideDateTime();
// var month = date.getMonth();
// var day = date.getDayOfMonth();
// if (month == 1 || month == 4 || month == 7 || month == 10)  
 
 
// Create a new catalog request
createRequest();
 
function createRequest() {
    var cart = new sn_sc.CartJS();
    var request = {
        'sysparm_id': '354c9968fbec269033c5ff57aeefdccb', // sys ID of catalog item SAP EFS Approval Hierarchy Review Data Upload
        'sysparm_quantity': '1',
        'variables': {
            'requested_for': '8e4d9138dbe1cb042686da94ce961924', //sys ID of Louise Gulliford 
            'short_description': 'Create SAP EFS Approval Hierarchy Review Data Upload',
            'description': 'Create SAP EFS Approval Hierarchy Review Data Upload',
        }
    };
 
    var cartDetails = cart.orderNow(request);
    updateRITM(cartDetails);
 
}
 
function updateRITM(cartDetails) {
 
 
    var ritm = new GlideRecord('sc_req_item');
    ritm.addQuery('request', cartDetails);
    ritm.query();
    while (ritm.next()) {
        current.sys_id = ritm.sys_id;
ritm.request.requested_for='8e4d9138dbe1cb042686da94ce961924';
        ritm.short_description = "Create SAP EFS Approval Hierarchy Review Data Upload ";
         
    
ritm.update();
 
 
}
}
 
{
    answer = true;
}
answer;

@nupur_goswami 

use this

orderNow function returns JSON object so updated the code to send the REQ sysId so that updateRITM function can query it correctly

// var answer = false;
// var date = new GlideDateTime();
// var month = date.getMonth();
// var day = date.getDayOfMonth();
// if (month == 1 || month == 4 || month == 7 || month == 10)  


// Create a new catalog request
createRequest();

function createRequest() {
    var cart = new sn_sc.CartJS();
    var request = {
        'sysparm_id': '354c9968fbec269033c5ff57aeefdccb', // sys ID of catalog item SAP EFS Approval Hierarchy Review Data Upload
        'sysparm_quantity': '1',
        'variables': {
            'requested_for': '8e4d9138dbe1cb042686da94ce961924', //sys ID of Louise Gulliford 
            'short_description': 'Create SAP EFS Approval Hierarchy Review Data Upload',
            'description': 'Create SAP EFS Approval Hierarchy Review Data Upload',
        }
    };

    var cartDetails = cart.orderNow(request);
    updateRITM(cartDetails.request_id);

}

function updateRITM(reqSysId) {

    var ritm = new GlideRecord('sc_req_item');
    ritm.addQuery('request', reqSysId);
    ritm.query();
    if (ritm.next()) {
        ritm.requested_for = '8e4d9138dbe1cb042686da94ce961924';
        ritm.short_description = "Create SAP EFS Approval Hierarchy Review Data Upload ";
        ritm.update();

        // update Requested for on REQ as well
        var req = ritm.request.getRefRecord();
        req.requested_for = '8e4d9138dbe1cb042686da94ce961924';
        req.update();

    }




}

{
    answer = true;
}
answer;

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

Chaitanya ILCR
Mega Patron

Hi @nupur_goswami ,

you should be able achieve this with flow designer 

and it's very easy to implement as well check

my last comment in the below post

https://www.servicenow.com/community/developer-forum/how-to-create-scheduled-task/m-p/3213788#M11892...

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya