Issue with Request state while creating via SOAP API using Cart API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 12:27 AM
Hello All
We have an Requirement to Create Request via Integration , for which I have constructed an Scripted SOAP , in the Same logic I had Included logic to Created Approval for the Same Request and have created BR to Auto Approve that
Now the Issue is , when ever we create Request via third party , Request is getting created with
- Request stateClosed Rejected
- StageClosed Incomplete
- StateClosed Incomplete
and later it is updating state as - Work in progress and Request State to Approved
below is the Logic which I have used in Scripted SOAP
function order() {
// Build cart and place order
var cart = new Cart();
for (var j = 0; j < cat_array.length; j++) {
var item = cart.addItem(cat_array[j] + '');
// Set variables from the JSON variables input
var invars = new JSONParser().parse(request.variables);
for (var i in invars) {
cart.setVariable(item, i, invars[i]);
}
}
var cartGR = cart.getCart();
cartGR.requested_for = requestedForUser;
// Place the order
cartGR.update();
var rc = cart.placeOrder();
var approval_gr = new GlideRecord('sysapproval_approver');
approval_gr.initialize();
approval_gr.state = 'requested';
approval_gr.approver = 'df33656e1bbae110a440ffb7d34bcbc7';
approval_gr.sysapproval = rc.sys_id; //Current is record that requires approval
approval_gr.document_id = 'Request :' + '' + rc.sys_id;
approval_gr.insert();
// Setting the description value for Request Record
var gr = new GlideRecord('sc_request');
gr.addQuery('sys_id', rc.sys_id);
gr.query();
if (gr.next()) {
gr.description = 'Automation';
gr.opened_by = opendby;
gr.update();
}
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request=' + rc.sys_id);
ritm.query();
while (ritm.next()) {
ritm.opened_by = opendby;
ritm.update();
}
}
Business rule to Auto Approve
var reqID='';
var gr = new GlideRecord('sc_request');
if(gr.get(current.sysapproval))
{
reqID = gr.getUniqueValue();
current.state='approved';
gr.request_state='in_process';
gr.stage = 'Requested';
gr.work_notes = 'Request has been Auto Approved';
gr.update();
current.update();
}
Expected Behavior when Request gets Created
Failure :
Can you please review and help to Make the Corrections if need
@Ankur Bawiskar @Anil Lande @jaheerhattiwale @Jaspal Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 12:14 AM
we are using Workflow only here , I was trying to add Timer condition before the Approval Activity as the Request generation is getting delayed from the SOAP , So I have added timer for 20 seconds before user Approval Activity , when I do that it is adding Approval History Multiple times which I'm unable to understand why , After adding this timer it is also adding for Manual requests which are created from Portal
I was trying to add following script in Timer but it is failing can you please take a look and suggest your solutions here
var requestsysid = workflow.scratchpad.requestID.toString();
var gr = new GlideRecord('sc_request');
gr.addQuery('sys_id', requestsysid);
gr.query();
if (gr.next()) {
if (gr.u_level_approval == 'df33656e1bbae110a440ffb7d34bcbc7') {
gs.info("entering into if loop");
answer = 20;
} else {
answer = 0;
}
}
it is not entering into if loop only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 01:21 AM
@Ankur Bawiskar can you also please take a look and correct if am wrong anywhere