mapping JSON feilds to importset table feilds

Its_Azar
Tera Guru

Hi team

 

im trying to map the feilds in the json req to my importset table feilds.

 

example json

{

test1 ="abc",

test2="cdf"

}

 

my import set fields that i want to map to above

 

u_test1

u_test2, how do i map these? i know its possible using scripted REST API but i want to use import set api for this, any insights are appreciated

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.




Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG

 Microsoft MVP (AI Services), India
7 REPLIES 7

Mohammad Danis3
Tera Expert

Hi @Its_Azar ,

After you receive the response you can trigger a import set API integration to your instance. It will automatically insert into your staging table and will run your transform map. 

 

Here is a sample script you can configure the same in flow actions.

 

//Create a JSON object to insert into your staging table for simplicity I have taken only one fields
var incJson = {
	"u_short_description":"test"      
};
var res = JSON.stringify(incJson);

try { 
 var r = new sn_ws.RESTMessageV2('test import set API', 'create incident'); // Repleace with your rest message name
 request.setRequestBody(res);
 var response = r.execute();
 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode();
 gs.log(responseBody);
}
catch(ex) {
 var message = ex.message;
}

 

Below is the rest message replace the rest end point with your staging name.

 

MohammadDanis3_0-1751632892925.png

 

Regards,
Mohammad Danish

hi there thanks for the response, but i dont want to use the rest message or scripted rest msg, is it possible to map the incoming json feilds to import set feilds manually?? without rest api or scripted rest

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.




Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG

 Microsoft MVP (AI Services), India

Mohammad Danis3
Tera Expert

@Its_Azar ,

Or you can Go to System Definition > Scheduled Jobs and create a new scheduled job. 
Here is the script for the scheduled job:

           

            var parsedResponse = JSON.parse(responseBody);
            var Data = parsedResponse.data;
 
 
            //Loop through each record and insert data into import set table
 
            for (var eachData in Data) {
var imprt = new GlideRecord("IMPORT SET TABLLE");
imprt.initialize();
imprt.setValue('u_field1',Data.field1);  
imprt.setValue('u_field2',Data.field2); 
imprt.insert();


};           


responseBody is your JSON Body.

Regards,
Mohammad Danish