- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2020 09:08 AM
Hello,
I'm facing an issue when i try to create my RITM using the Scripted Rest API i have every time the opened_by and resquestd_for fields with geust value ?
Note:
- Basic Authentification used (user have all role, admin, security admin, rest.....)
- No ACL configured.
- The sys_properties: glide.basicauth.required.api is true
Thanks for your help!
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 05:23 AM
try below
createRequest: function() {
var cart = new Cart();
var item = cart.addItem(this.cat_item_id);
var rc = cart.placeOrder();
var req = new GlideRecord('sc_request');
req.get(rc.sys_id);
req.opened_by = this.opened_by // make sure to pass sys_id of user
req.requested_for = this.requestor; // make sure to pass sys_id of user
req.update();
var req_numb = rc.number;
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", rc.sys_id);
gr.query();
if (gr.next()) {
gr.company = this.company;
gr.short_description = this.short_description;
gr.description = this.description;
gr.cat_item = this.cat_item_id;
gr.state = this.state;
gr.active = true;
gr.opened_by = gr.request.opened_by;
gr.correlation_id = this.cloud_id;
gr.state = 0;
try {
gr.update();
} catch (exception) {
this.addError('UNDEFINED', exception.toString());
}
this.respObj.status = 'ok';
this.respObj.number = gr.number;
this.respObj.sysid = gr.sys_id;
} else {
this.addError('UNDEFINED', 'The system encountered an error.');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2020 09:41 AM
Can you share the code? on how you are creating it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 01:08 AM
Hello;
this is the function used to create my request:
All this variables return value before this function, but when i put my gs.log here i have undifiened example for the "this.requestor"
gs.log("sys_id for this.requestor "+this.requestor);//i have a good value in the log
createRequest: function() {
var cart = new Cart();
var item = cart.addItem(this.cat_item_id);
var rc = cart.placeOrder();
var req_numb = rc.number;
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", rc.sys_id);
gr.query();
if (gr.next()) {
gs.log("Line 147 sys_id for this.requestor "+this.requestor);//i have undifined in the log
gr.request.requested_for = this.requestor ;//this.requested_for//// i have try also with an sys_id but is already is guest and in the log i have undifiened
gr.company = this.company;
gr.short_description = this.short_description;
gr.description = this.description;
gr.cat_item = this.cat_item_id;
gr.state = this.state;
gr.active = true;
gr.opened_by = gs.getUserID();// i have try with the sys_id but is already is guest and in the log i have undifiened
gr.correlation_id = this.cloud_id;
gr.state = 0;
try {
gr.update();
} catch (exception) {
this.addError('UNDEFINED', exception.toString());
}
this.respObj.status = 'ok';
this.respObj.number = gr.number;
this.respObj.sysid = gr.sys_id;
} else {
this.addError('UNDEFINED', 'The system encountered an error.');
}
},

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 05:23 AM
try below
createRequest: function() {
var cart = new Cart();
var item = cart.addItem(this.cat_item_id);
var rc = cart.placeOrder();
var req = new GlideRecord('sc_request');
req.get(rc.sys_id);
req.opened_by = this.opened_by // make sure to pass sys_id of user
req.requested_for = this.requestor; // make sure to pass sys_id of user
req.update();
var req_numb = rc.number;
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", rc.sys_id);
gr.query();
if (gr.next()) {
gr.company = this.company;
gr.short_description = this.short_description;
gr.description = this.description;
gr.cat_item = this.cat_item_id;
gr.state = this.state;
gr.active = true;
gr.opened_by = gr.request.opened_by;
gr.correlation_id = this.cloud_id;
gr.state = 0;
try {
gr.update();
} catch (exception) {
this.addError('UNDEFINED', exception.toString());
}
this.respObj.status = 'ok';
this.respObj.number = gr.number;
this.respObj.sysid = gr.sys_id;
} else {
this.addError('UNDEFINED', 'The system encountered an error.');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 06:50 AM
Hello,
Good, it' swork now for the opened_by and requestor_for but i have already the created_by is guest !
I also added it here:
req.sys_created_by = this.requestor.getDisplayValue(); // I have a sys_id not display value of user
Have you any idea if it's related to servicenow security policy or other reason?
Thanks in advance