How to convert JSON values using HTML tags , in a Rest call message?

yogesh15dd
Tera Guru

Hi,

I have set up an integration between Service Now and Slack for sending notifications to slack whenever there is a request created in Service Now, i'm successful in sending the notifications, but can't decorate the notifications message using   HTML tags, for example in the below 'text' i would like to make the 'Short description', 'Product Name' and 'Inquiry Type' as a bold texts and many other things.

Passing <b> </b> is not helping.

Any idea pls?

Script part:

var slack = new SlackMessageCC();

slack.payload.text = 'A new request has been assigned to ' + current.assignment_group.name + '. Please follow the link for more information.';

slack.payload.icon_emoji = ':exclamation:';

slack.payload.attachments.push({

    'title': current.number.toString(),

      'title_link': 'https://' + gs.getProperty('instance_name') + '.service-now.com/nav_to.do?uri=sc_request.do?sys_id=' + current.sys_id,

    'text':"<b>Short Description : <\/b>"+current.short_description.toString()+"\nProduct Type : "+current.u_product_name+"         Inquiry Type : "+current.u_inquiry_type+"         Location : "+current.location.name

});

slack.send();

Current Output what i'm getting is

find_real_file.png

Thanks

Yogesh Dafedar

1 ACCEPTED SOLUTION

This should work



'text':"*Short Description* : "+current.short_description.toString()+"\n*Product Type* : "+current.u_product_name+"         *Inquiry Type* : "+current.u_inquiry_type+"         *Location* : "+current.location.name



Below are few slack tips



22 Handy Slack Hacks Everyone Should Know


View solution in original post

9 REPLIES 9

yogesh15dd
Tera Guru

@ctomasi , any thoughts?



Thanks



Yogesh


You will need to translate your HTML in to the Slack formatting.



https://api.slack.com/docs/message-formatting#message_formatting


Thanks Chuck, that helped


Slight modification to observe best practices. Rather than dot-walking to location.name, use getDisplayValue(). Also, when possible, use getValue('field_name') to get the value, not a copy of the object. The more you use them, the fewer problems you will find.



'text':"*Short Description* : "+current.getValue('short_description') + "\n*Product Type* : " + current.getValue('u_product_name') + "         *Inquiry Type* : " + current.getValue('u_inquiry_type') + "         *Location* : " + current.location.getDisplayValue();