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

If you want whole thing done by requested for then you can add below right before var cart. All scripts are run by guest account unless you use below

var user = new GlideRecord(‘sys_user’);

if(user.get(this.requestor)){
gs.getSession().impersonate(user.sys_id);
}

imed1
Tera Contributor

Very nice ist's work perfectelly by this option.

 

another stronge behavior, when i launch my request from my third party if it's finished with error the user is "locked out" ?

 

 

Make sure the user that you are passing is not locked out.

imed1
Tera Contributor

No have an admin role, and is my user !

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!