Create RITM vai cart API

Prashant52
Tera Contributor

Hi Developers,

I want to create a RITM when record producer submitted up and few values from record producer should be populated on catalog item.

RITM have field 

Name

Description

Short description 

Submit 

from backend Catalog item "Submit IT request" have fields Requested For, Description and Short description should be autopulated from Name, Description and Short description respectively. Catalog item is not visible to end user .

Client script on Record producer-

function onSubmit() {
//Type appropriate comment here, and begin script below
var userID = g_form.getValue('requested_for');
var shortDesc = g_form.getValue('short_description');
var Desc = g_form.getValue('description');

var ga = new GlideAjax('pkkRequest');
ga.addParam('sysparm_name', 'createRequest');
ga.addParam('sysparm_userID', "userID");
ga.addParam('sysparm_shortDesc', "shortDesc");
ga.addParam('sysparm_Desc', "Desc");
ga.getXML(HelloWorldParse);

}

function HelloWorldParse(response) {
}

 

SI : pkkRequest

createRequest: function() {

var userID = this.getParameter('sysparm_userID');
var shortDesc = this.getParameter('sysparm_shortDesc');
var Desc = this.getParameter('sysparm_Desc');
var cart = new sn_sc.CartJS();
var request1 = {
'sysparm_id': 'ec10f4fd47266110b81cd855d36d4308', // sys_id of catalog item
'sysparm_quantity': '1',
'variables': {
'requested_for': userID, //'8efae6cbdb038b00d6563cae7c961
'short_description': shortDesc,
'description': Desc
}
};

var checkoutInfo = cart.checkoutCart();
var cartDetails = cart.orderNow(request);
var requestDetails = cart.submitOrder(request);
},

 

RITM is being created but dynamically values are not getting populated on ritm variables 

 

Appreciate in advance 

 

Thanks

Kaushal

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Prashant52 

why to do this in onSubmit and use GlideAjax?

You can simply do this in Record producer script and replace the values dynamically

Use this script in Record producer script

var cart = new sn_sc.CartJS();
var request1 = {
	'sysparm_id': 'ec10f4fd47266110b81cd855d36d4308', // sys_id of catalog item
	'sysparm_quantity': '1',
	'variables': {
		'requested_for': producer.requested_for, //'8efae6cbdb038b00d6563cae7c961
		'short_description': producer.short_description,
		'description': producer.description
	}
};

var checkoutInfo = cart.checkoutCart();
var cartDetails = cart.orderNow(request);
var requestDetails = cart.submitOrder(request);

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

5 REPLIES 5

Amit Gujarathi
Giga Sage
Giga Sage

HI @Prashant52 ,
I trust you are doing great.
To accomplish this, you can use a client script on the record producer that will retrieve the necessary field values and pass them to a GlideAjax function, which will create the RITM and populate the catalog item fields accordingly. Here is an example client script:

function onSubmit() {
    var userID = g_form.getValue('requested_for');
    var shortDesc = g_form.getValue('short_description');
    var Desc = g_form.getValue('description');

    var ga = new GlideAjax('pkkRequest');
    ga.addParam('sysparm_name', 'createRequest');
    ga.addParam('sysparm_userID', userID);
    ga.addParam('sysparm_shortDesc', shortDesc);
    ga.addParam('sysparm_Desc', Desc);
    ga.getXML(HelloWorldParse);
}

function HelloWorldParse(response) {
    // Any necessary parsing logic can be added here
}
createRequest: function() {
    var userID = this.getParameter('sysparm_userID');
    var shortDesc = this.getParameter('sysparm_shortDesc');
    var Desc = this.getParameter('sysparm_Desc');
    var cart = new sn_sc.CartJS();

    var request = {
        'sysparm_id': 'ec10f4fd47266110b81cd855d36d4308', // sys_id of catalog item
        'sysparm_quantity': '1',
        'variables': {
            'requested_for': userID,
            'short_description': shortDesc,
            'description': Desc
        }
    };

    var checkoutInfo = cart.checkoutCart();
    var cartDetails = cart.orderNow(request);
    var requestDetails = cart.submitOrder(request);
},

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi