- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 03:24 AM
I am processing a third-party response according to the requirements. However, as shown below, I am sending the required parameters to the array as a string, but I want each parameter printed on a separate line.
But its not happening instead I am getting as shown in second pic. why?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 04:33 AM - edited 05-07-2025 04:34 AM
Do not use JSON.stringify at the end, it will make \n as character rather than line break.
So, try with below code, it will work:
var currentdate = new GlideDate();
var request = new sn_ws.RESTMessageV2("Power Automate Dataverse API", "Get Approval Responses");
request.setStringParameter("envName", gs.getProperty("power_automate.environmentName"));
request.setStringParameter("AppName", gs.getProperty("power_automate.applicationName"));
request.setStringParameter("ModifiedOn", currentdate);
response = request.execute(); // Trigger or Execute the rest message targeted to get the approval responses.
gs.log("Power Automate dataverse - endpoint is: " + request.getEndpoint());
httpResponseStatus = response.getStatusCode();
var responseBody = response.getBody(); // get the approval responses as a body upon successful execution of the rest message
var httpStatus = response.getStatusCode();
var response_json = JSON.parse(responseBody);
gs.log("Power Automate dataverse -status code is :" + httpStatus);
gs.log("Power Automate dataverse - response body is :" + responseBody);
for (i = 0; i < response_json.value.length; i++) { // looping the body to process the all the approval responses
var notes = "";
var approval_tasks = new GlideRecord("sc_task");
approval_tasks.addEncodedQuery("state=2^sys_id=" + response_json.value[i].msdyn_flow_approval_category); // get the task where state equals to Inprogress with corresponding sysID
approval_tasks.query();
if (approval_tasks.next()) {
if (response_json.value[i].msdyn_flow_approval_result == 'Approve') { // check if the approval request status is approved
approval_tasks.setValue('state', '3'); //set the sc task state to closed completed
} else if (response_json.value[i].msdyn_flow_approval_result == 'Reject') { // check if the approval request status is rejected
approval_tasks.setValue('state', '7'); //set the sc task state to closed rejected
}
notes=
"Approver Name : " +response_json.value[i].msdyn_flow_approvalrelationship_approvalresponses[0]["_ownerid_value@OData.Community.Display.V1.FormattedValue"]+"\n"+
"Approval Status : " +response_json.value[i].msdyn_flow_approvalrelationship_approvalresponses[0].msdyn_flow_approvalresponse_response+"\n"+
"Comments : " +response_json.value[i].msdyn_flow_approvalrelationship_approvalresponses[0].msdyn_flow_approvalresponse_comments; //Push approver name, response and comments to array
approval_tasks.work_notes = notes; //update task worknotes with notes array
approval_tasks.update();
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 05:11 AM
it's notes data so no need to use stringify, update this line
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 03:29 AM
are you pushing that to work notes or any journal field?
if yes then you need to give the values in [code][/code] and then use <br/> to give new line
can you give complete requirement? with which system you are integrating? are you connecting to another ServiceNow instance?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 04:08 AM - edited 05-07-2025 04:08 AM
Yes I am pushing the value to work notes.
yup I gave "[code]<br />[/code]" working but same not working if I want to join the values with one line gap in array.? "[code]<n/>[/code] does this won't work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 04:15 AM
share the complete code and what's your expected outcome?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 04:20 AM - edited 05-07-2025 04:26 AM
var currentdate = new GlideDate();
var request = new sn_ws.RESTMessageV2("Power Automate Dataverse API", "Get Approval Responses");
request.setStringParameter("envName", gs.getProperty("power_automate.environmentName"));
request.setStringParameter("AppName", gs.getProperty("power_automate.applicationName"));
request.setStringParameter("ModifiedOn", currentdate);
response = request.execute(); // Trigger or Execute the rest message targeted to get the approval responses.
gs.log("Power Automate dataverse - endpoint is: " + request.getEndpoint());
httpResponseStatus = response.getStatusCode();
var responseBody = response.getBody(); // get the approval responses as a body upon successful execution of the rest message
var httpStatus = response.getStatusCode();
var response_json = JSON.parse(responseBody);
gs.log("Power Automate dataverse -status code is :" + httpStatus);
gs.log("Power Automate dataverse - response body is :" + responseBody);
for (i = 0; i < response_json.value.length; i++) { // looping the body to process the all the approval responses
var notes = [];
var approval_tasks = new GlideRecord("sc_task");
approval_tasks.addEncodedQuery("state=2^sys_id=" + response_json.value[i].msdyn_flow_approval_category); // get the task where state equals to Inprogress with corresponding sysID
approval_tasks.query();
if (approval_tasks.next()) {
if (response_json.value[i].msdyn_flow_approval_result == 'Approve') { // check if the approval request status is approved
approval_tasks.setValue('state', '3'); //set the sc task state to closed completed
} else if (response_json.value[i].msdyn_flow_approval_result == 'Reject') { // check if the approval request status is rejected
approval_tasks.setValue('state', '7'); //set the sc task state to closed rejected
}
notes.push(
"Approver Name : " +response_json.value[i].msdyn_flow_approvalrelationship_approvalresponses[0]["_ownerid_value@OData.Community.Display.V1.FormattedValue"]+"[code]<br />[/code]"+
"Approval Status : " +response_json.value[i].msdyn_flow_approvalrelationship_approvalresponses[0].msdyn_flow_approvalresponse_response+"[code]<br />[/code]"+
"Comments : " +response_json.value[i].msdyn_flow_approvalrelationship_approvalresponses[0].msdyn_flow_approvalresponse_comments
); //Push approver name, response and comments to array
approval_tasks.work_notes = JSON.stringify(notes); //update task worknotes with notes array
approval_tasks.update();
I am expecting the work notes should populate as below