Issue with Request state while creating via SOAP API using Cart API

shyam34
Tera Contributor

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 

shyam34_0-1702628699902.png

 

Failure :

shyam34_1-1702628748800.png

 

Can you please review and help to Make the Corrections if need

 

@Ankur Bawiskar @Anil Lande @jaheerhattiwale @Jaspal Singh 

 

 

 

6 REPLIES 6

shyam34
Tera Contributor

@Ankur Bawiskar , can you please take a look?

Anil Lande
Kilo Patron

Hi,

Check the flow/workflow running on your catalog item. 

There is possibility of flow/workflow setting it rejected. 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

@Anil Lande  ,

 

Yes your correct Workflow is getting Conflicted and moving the State to Rejected 

 

now In order to Resolve this I have added timer before the user Approval Activity and this resolved the issue but we could see Approval history is getting Twice which wasn't got added before(that is before adding timer)

 

shyam34_0-1704303418414.png

can you please help me in understanding why this is getting added

 

 

Hi,

No Idea, looks like there are many configurations in your instance that need to be checked. 

Is there any Flow used?

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande