To insert or update fields in a table using API

zabeeulla2
Kilo Expert

HI All,

I have a Requirement where I get some field inputs from third party and then I need to insert or update those fields in a table present in SNOW, as there are huge number of fields and there is a scope of new fields getting added up in near future, so unable to map them one to one, instead I need to code the logic, This is done using scripted web service.

I am able to retrieve the field by using the following lines of code but unable to set those all fields accordingly in the table. Please find the code below.

  var xmlDocInflight= new XMLDocument(soapRequestXML);

  var nodelistInflight = xmlDocInflight.getNodes("//execute/*");

  for (var nodeCountInflight=0;nodeCount1<nodelistInflight.getLength();nodeCountInflight=nodeCountInflight+1) {

    //script include call.

}

In the above 'for' loop I thought of calling a script include where this mapping or logic should be written.

Immediate help is appreciated.

Regards,

Zabeeulla.

2 REPLIES 2

ramireddy
Mega Guru

Hi,



SNOW has a default script include "Importsetutil", which has a similar type of code, copy data from one table another table, without hard-coding the field names. It iterates through source table fields and updates those values in target table. Please go through that script include,


Hi Ram,



Thank you for the quick response but here the scenario what I have is I am getting the parameters but unable to set them in the column as I am unable to check the column in that table.


please check the code below;


updateRitmVariable :function (requested_item, field_name,Value){



}



In the above function I get the variable name which matches with the column name of snow table, now what I need is to assign the corresponding value to the field present in the table.



I have tried writing the below lines by referring to importsetutil in the background job:



test();


function test(){


var a = new GlideRecord('u_ptp_product_services');


a.initialize();


var attrs = new Packages.java.util.HashMap();


var fields =a.getFields();


for (var i = 0; i < fields.size(); i++) {


var field = fields.get(i);


var type = field.getED().getInternalType();


var fname = field.getName();


attrs.put(fname, 'asdfds');


}


a.insert();


}



But No luck. The record gets inserted but all fields are empty



Can you please suggest further.



Regards,


Zabeeulla.