Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Post a REST Message without escaping any special characters, possible?

andy_dufresne
Tera Expert

Hello Gurus,


I have been trying this for 2 days now almost about to give up ...

I need to insert EXACTLY this text object [should not be parsed, should not be escaped no changes to be made in the target but just this] in the table 'x_mioms_microsoft_oms_incident'

------------------------------------------------

Alert : Azure: Activated Severity: 0 SVC1111111 :donate Severity Test 0 
version : 2.0
properties : 
status : Activated
context : {
"timestamp": "2018-11-27T12:45:09.3657877Z",
"id": "/subscriptions/8999dec3-0104-4a27-94ee-6588559729d1/resourceGroups/:donate-prod/providers/microsoft.insights/chetricsAlerts/SVC1111111%20:donate%20Severity%20Test%200",
"name": "SVC1111111 :donate Severity Test 0",
"description": ":donate App Insights Test. Failed page requests > 1 in 5 minutes. Severity 0 test. ",
"conditionType": "SingleResourceMultipleMetricCriteria",
"severity": "0",
"condition": {
"windowSize": "PT3333M",
"allOf": [
{
"metricName": "requests/failed",
"metricNamespace": "Microsoft.Insights/components",
"operator": "GreaterThan",
"threshold": "1",
"timeAggregation": "Maximum",
"metricValue": 15.0,
"dimensions": [
{
"name": "ResourceId",
"value": "413241234327-c250-4efd-b3a7-1e77fasfdasdfasfdad374aba8"
},
{
"name": "request/success",
"value": "False"
}
]
}
]
},
"subscriptionId": "asdfasfadsf-adfasdf-asdfasdf-asdfasdf-asdfasfda",
"resourceGroupName": ":donate-prod",
"resourceName": ":donate-prod",
"resourceType": "Microsoft.Insights/components",
"resourceId": "/subscriptions/8999dec3-0104-4a27-94ee-6588559729d1/resourceGroups/:donate-prod/providers/Microsoft.Insights/components/:donate-prod",
"portalLink": "https://designate/somelink/someother link"
}

Link not present



To do this I have manually placed this in an incident table record under 'description'. So that I can invoke when I need it using the following background script

 

var gr = new GlideRecord('incident');
gr.get('fd10d30cdb966b00edfc7cbdae96197d');

 

and I'm using the following code to populate the description:

var restMessage = new sn_ws.RESTMessageV2();
restMessage.setBasicAuth("<username>", "password");
restMessage.setHttpMethod("post");
restMessage.setEndpoint("http://<instancename>.service-now.com/api/now/table/x_mioms_microsoft_oms_incident");

var testVar1 = "{\"description\" : "+ gr.description +"}";
restMessage.setRequestBody(testVar1);
var response = restMessage.execute();
gs.print(response);

The above script jumbles up all the record and populates the following in the 'description' of the 'x_mioms_microsoft_oms_incident' table:

 

{description={Alert=Azure: Activated Severity: 0 SVC1111111 donate Severity Test 0, version=2.0, properties=, status=Activated, context={timestamp=2018-11-27T12:45:09.3657877Z, id=/subscriptions/asdfads-0104-4asdfasdfa27-9adsfasdf4ee-6588559asdfasdf729d1/resourceGroups/donate-prod/providers/microsoft.insights/metricAlerts/SVC1111111%20donate%20Severity%20Test%200, name=SVC1111111 donate Severity Test 0, description=donate App Insights Test. Failed page requests > 1 in 5 minutes. Severity 0 test. , conditionType=SingleResourceMultipleMetricCriteria, severity=0, condition={windowSize=PT5M, allOf=[{metricName=requests/failed, metricNamespace=Microsoft.Insights/components, operator=GreaterThan, threshold=1, timeAggregation=Maximum, metricValue=15.0, dimensions=[{name=ResourceId, value=asdfa-c250-4efd-b3a7-1e77f374aba8}, {name=request/success, value=False}]}]}, subscriptionId=8999dec3-0104-4a27-94ee-6588559729d1, resourceGroupName=donate-asdfasf, resourceName=donate-asdfasdf, resourceType=Microsoft.Insights/components, resourceId=/subscriptions/8999dec3-0104-4a27-94ee-6588559729d1/adsfasdf/donate-prod/providers/Microsoft.Insights/components/donate-prod, portalLink=https://asdfadf.asdfasdf.asdfasdf/#resource/subscriptions/asdfasdf-0104-4a27-94ee-asdfasdf/resourceGroups/donate-prod/providers/asdfadf.Insights/asdfasdf/donate-prod}}}



Question: As you can see my original text and the output above are not identical [all quotes and colons were escaped], what should I change in the code above to generate proper responses.  

 

It has to be  only REST option to populate data as I will be using this towards Integration.

Thanks a million for the help!

 

1 REPLY 1

Ajaykumar1
Tera Guru