current.setValue() or current.field_value is not working

Madhusagar Pal1
Tera Expert

Hi All ,

Good evening

My query is I am fetching the Jira key, id, and statuscode from the response body and updating the same values in the below incident form.

MadhusagarPal1_0-1680699082823.png

 

I have create Async business rule, code is below

(function executeRule(current, previous /*null when async*/ ) {

 

    var req_boby = "{\"fields\":{\"project\":{\"key\":\"JIR\"},\"summary\":" + "\"" + current.short_description + "\",\"issuetype\": {\"name\": \"Task\"}}}";

 

    var request = new sn_ws.RESTMessageV2('Snow_to_JIRA_Integration', 'CreateIncident');

    request.setEndpoint('https://sagaras400.atlassian.net/rest/api/3/issue');

    request.setHttpMethod('POST');

    request.setRequestBody(req_boby);

 

    request.setBasicAuth('sagaras400@gmail.com', 'ATATT3xFfGF0TImb89VZ_qdM8n1Co38t8XIPX2VTT9Aty25np9s_frBWdwguGMry7y0ceVpdjUGVNNjv7q7jFQYvFBQUcwqudY7ndyE1j_QWebD9rIlVv1o4zYQd-0o95YlIuL4Ct701bnxroIBNK-Ot2jYMTkzDN8ay8tcewZHbDQTxGI7yDag=E3CB3A77');

 

    request.setRequestHeader('Accept', "application/json");

    request.setRequestHeader("Content-Type", "application/json");

 

    var response = request.execute();

               var responseBody = response.getBody();

    var httpStatus = response.getStatusCode();

              

               var body = JSON.parse(responseBody);

              

//            current.setValue('u_key',body.key);

//            current.setValue('u_id',body.id);

//            current.setValue('u_httpstatuscode',response.getStatusCode());

              

               current.u_key = body.key;

               current.u_id = body.id;

               current.u_httpstatuscode = httpStatus;

               current.u_jirakey = body.key;

              

    gs.log(body.id);

               gs.log(body.key);

               gs.log(httpStatus);

 

 

 

})(current, previous);

 

But the values are not updating in the incident form. I used current.field = PassValue and current.setValue() both methods however it is not working.

But the values I can captured in system log, because I used gs.log()

MadhusagarPal1_1-1680699082838.png

 

JIRA :

MadhusagarPal1_2-1680699082845.png

 

I would request please let me know what was wrong in my code.

3 ACCEPTED SOLUTIONS

Prince Arora
Tera Sage
Tera Sage

@Madhusagar Pal1 ,

 

I think you have missed current.update in your script

As you have set all the values, you need to mention "current.update()", just to update the record

 

current.u_key = body.key;

current.u_id = body.id;

current.u_httpstatuscode = httpStatus;

current.u_jirakey = body.key;

current.update();

 

Meanwhile, you have written a correct script, happy coding 🙂

 

Please mark this answer as helpful + accept it if it has answered your query!

View solution in original post

Hi Mehta,

 

Thanks for quick response. It work for me 🙂

Regards,

Madhu.

View solution in original post

Hi @Madhusagar Pal1 , 

 

happy that it worked out for you.

Can you mark my answer as correct or helpful.

View solution in original post

7 REPLIES 7

Yes Mehta ,

 

before current.update () we need to use current.setWorkFlow(false). Otherwise it is going into infinite loop.

@Madhusagar Pal1 

 

This would be the case with : After - update business rule 

for async it should work fine without setWorkflow()

@Madhusagar Pal1 ,

 

I have also answered correctly your query on the same time, it just a clash of few seconds

Meanwhile! you can accept multiple solutions for a question