Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

on after Transform Map Script not working

Vamshi_ch123
Tera Contributor

Hi All,

 

I'm importing the data to cmdb_ci table so based on class this will also get updated in alm_asset table.

Now I'm trying to update the status field of alm_asset table since it is not directly available in cmdb_ci, For this I'm writing a onafter transform script as below but which is not working/updating the status

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

var status = source.u_status;
    var gr = new GlideRecord("alm_asset");
    gr.addQuery('serial_number', source.u_serial_number);
    gr.query();
    while(gr.next()) {
        if (status == "Assigned To Employee" || status == "Assigned To Location" || status == "Available" || status == "Received - Awaiting Eval") {
            gr.install_status = '6';
        } else if (status == "In Transit - Outbound" || status == "In Transit - Returning") {
            gr.install_status = '9';
        } else if (status == "Damaged") {
            gr.install_status = '3';
        } else if (status == "Disposed" || status == "Delete") {
            gr.install_status = '7';
        }
		else if (status == "Pending Retrieval"){
            gr.install_status = '1';
        }
		else if (status == "Missing"){
            gr.install_status = '8';
        }
        gr.update();
    }
})(source, map, log, target);

Vamshi_ch123_0-1725261849985.png

 

Thank you

1 REPLY 1

Najmuddin Mohd
Mega Sage

HI @Vamshi_ch123 ,

I believe the script is fine. But, why While loop,  when there will be only one record which will be retrieved with the serial number.
I would advise you to add log messages for var status to actually get the values what it's actually coming.

Hope this helps.

Regards,
Najmuddin.