Setting requested for field using Cart API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2017 01:55 PM
Hi,
I'm working on a script that will created request item. i found the cart API, which seems like a good way to achieve it, including the option to set values in variables.
However, i'm not sure how i can set fields values (not variables) using the API -Service Catalog Script API - ServiceNow Wiki
For example, i would like to set a value for the requested for field.
Anyone know how do to it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2017 03:32 PM
Hello,
I think you might have to modify the OOTB script include "Cart", as this is the instantiated class. 😞 ...(I kind of sometimes dont like doing this, because updates to this class get missed when you upgrade to a newer version). Its your call !
This is what i did OOTB in istanbul.
Go to script include called 'Cart'.
Replace the method
getCart: function() {
var cart = GlideappCart.getCartForRhino(this.cartName, this.userID);
var record = cart.getGlideRecord(); // gets the new glide record item
record.setValue('requested_for', this.userID); // set the requested for
record.update(); // enforce the update
return record; //return the new object
},
This is what i used to create a new item
var cart = new Cart('e2132865c0a8016500108d9cee411699','62826bf03710200044e0bfc8bcbe5df1'); // sys id of item and user (abel tuter);
cart.addItem('e2132865c0a8016500108d9cee411699'); // add item
cart.placeOrder();
gs.addInfoMessage(cart.number);
Good Luck ! Let me know if it work.
Narinder Guru
SN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2017 03:37 PM
By the way you can see which scripts are not upgraded in the upgrade log, so you can always force it to use the new version