Scripted Rest API: Create RITM and SCTASK

imed1
Tera Contributor

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!

1 ACCEPTED SOLUTION

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.');
    }
}

View solution in original post

17 REPLIES 17

can you share full code?

imed1
Tera Contributor

I use this function in my Scripted Rest API:

updateTask: function() {
try {
this.task.comments = this.comment;
this.task.update();
this.respObj.status = 'ok';
} catch (exception) {
this.addError('UNDEFINED', 'The system encountered an error. Aborting action.');
}

}

imed1
Tera Contributor

Hello,

 

The same issue on update, i have a Guest user instead the user was sent the Task updates.

 Any idea?

Thanks in advance!