How to put to a freshdesk custom field, from serverless app, using a value from the response body of a successful post

Hi,
I am creating a serverless app that creates an incident in service now using ticketcreate event.

I receive a response which contains a crucial piece of info for when it comes time to update the correct service now incident.

I have parsed that info and gotten the value I require which identifies the incident i wish to “put” changes into.

Problem : i wish to make this into a global variable for use which i cannot seem to do so instead I was hoping to put it into a custom field in the freshdesk ticket as a way to store it and get it later for updates but i can’t seem to figure out how to do a put to the freshdesk ticket to update the custom field.

I am using node and javascript as the documentation indicates for serverless apps but the api samples in the docs are all in curl commands, im new to this so i just don’t understand how these samples help or how to implement them.

So from a serverless app using node.js and javascript, how do you do a ‘put’ to a freshdesk ticket in your domain?

below is the script. it includes mapping which can be ignored and is here to show the full code.

onTicketCreateCallback : function(args) {
// getting ticket id number
var freshDeskID = args[‘data’][‘ticket’][‘id’];

	//Mapping Freshdesk JSON into ServiceNow
	let resultmap = transform({
		subject: args['data']['ticket']['subject'],
		description_text: args['data']['ticket']['description_text'],
		status: args['data']['ticket']['status'],
		priority: args['data']['ticket']['priority'],
		id : args['data']['ticket']['id'],
		 cf_assignment_group_1589796: args['data']['ticket']['custom_fields']['cf_assignment_group_1589796'],
		cf_business_service_1589796: args['data']['ticket']['custom_fields']['cf_business_service_1589796'],
		cf_category_1589796: args['data']['ticket']['cf_category_1589796'],
		cf_subcategory_1589796: args['data']['ticket']['cf_subcategory_1561437'],
		cf_urgency_1589796: args['data']['ticket']['custom_fields']['cf_urgency_1589796'],
		cf_impact_1589796: args['data']['ticket']['custom_fields']['cf_impact_1589796'],
		cf_location_1561437: args['data']['ticket']['custom_fields']['cf_location_1589796'],
		}, { 
		item: {	  
			incident_state: 'status',
			priority: 'priority',
			description: 'description_text',
			short_description: 'subject',
			u_freshdesk_id : 'id',
			assignment_group: 'cf_assignment_group_1589796',
			business_service: 'cf_business_service_1589796',
			category: 'cf_category_1589796',
			urgency: 'cf_urgency_1589796',
			impact: 'cf_impact_1589796',
			location: 'cf_location_1589796'
		}
	});


	
	let headers = {'Authorization' : "Basic " + " username and password in base64"};
	let reqBody = JSON.stringify(args);
	let options = {headers: headers, body: reqBody};

	//posting the data and creating the ticket in serviceNow
	$request.post("https://domain.service-now.com/api/now/table/incident",options)

	.then(function(data)  {
		console.log('Successfully created task in SNOW' + JSON.stringify(data));

                    //parsing the response and getting ticket id in service now (sys_id)
		let parsed = JSON.parse(data.response);
		var sys_id = parsed.result.sys_id;
		console.log(" sys_id = " + sys_id);  

                 // NOW I WISH TO PUT THIS "SYS_ID" INTO A CUSTOM STRING FIELD IN THE FRESHDESK TICKET. WHAT IS THE CORRECT WAY OF DOING THIS? IS THERE A BETTER WAY?

	},

Thank you

Hey Craig!

If this is your problem can you try to use $db.set to set the value from the service now’s response to the app’s database and retrieve whenever needed? I hope it works better than storing it in a custom field in Freshdesk

Reference: Freshworks Developer Docs | Freshworks app ecosystem

Let me know if this works! :smiley:

2 Likes

This worked, Thank you very much!