Fields in the target table are not updating

Manasa23
Tera Contributor

HI,

I have written the below OnBefore script on Transform map on Hardware table. However it is not working ..
If both the assigned to and loc is empty then below target fields mentioned should update and if the assigned to or loc is empty , the the fields in target table should update.

Need Help !


if ((source.u_assign_to == "") && (source.u_loc == "")) {

target.assigned_to = "";
target.managed_by = "";
target.owned_by = "";
target.u_loc = "";
target.install_status = "6";
target.substatus = "1";
} else
if (source.u_assign_to != "" || source.u_loc != "") {
target.install_status = "1";
target.stockroom = "";
target.u_inuse = true;
}

Thanks,
M

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi @manasa

Your script is incorrect. Please use the modified version below:

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

    // Add your code here
    if (JSUtil.nil(source.u_assign_to) && JSUtil.nil(source.u_loc)) {
        target.assigned_to = "";
        target.managed_by = "";
        target.owned_by = "";
        target.u_loc = "";
        target.install_status = "6";
        target.substatus = "1";
    } else {
        target.install_status = "1";
        target.stockroom = "";
        target.u_inuse = true;
    }

})(source, map, log, target);

Let me know if you are facing an issue. Would suggest to make use of JSUtil to check if value of source field is empty or not, I am saying this from my personal practical experience as sometimes "== blank' did not work for me. So I recommend using JSUtil.nil or JSUtil.notNil to check for empty or non empty values.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

6 REPLIES 6

Rajat_Choudhary
Tera Expert

Hi Manasa, Could you please try using This below code inspite of directly using the glide record in place of target

Refer the code below-

var gr = new GlideRecord('target.table_name');
gr.get(target.sys_id);


if ((source.u_assign_to == "") && (source.u_loc == "")) {

	gr.setValue(assigned_to, "");
	//change
	for below fields also..
	target.managed_by = "";
	target.owned_by = "";
	target.u_loc = "";
	target.install_status = "6";
	target.substatus = "1";
	gr.update();
} else if (source.u_assign_to != "" || source.u_loc != "") {
	gr.setValue(install_status, "1");
	//change
	for below fields also..
	target.stockroom = "";
	target.u_inuse = true;
	gr.update();
}

If the problem persists, could you please check and share the comments from transform history.

Please mark the answer as helpful and correct if it resolves the issue.

Hope this answers will be helpful.
Please mark the answer as helpful and correct.

Best Regards,
Rajat Choudhary

Manasa23
Tera Contributor

Thanks Rajat.. let me try 

You are welcome..best wishes..
Hope this answers will be helpful.
Please mark the answer as helpful and correct.

Best Regards,
Rajat Choudhary

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

Only issue is as below

if ((source.u_assign_to == "") && (source.u_loc == "")) {

target.assigned_to = "";
target.managed_by = "";
target.owned_by = "";
target.u_loc = "";
target.install_status = "6";
target.substatus = "1";
} else
if (source.u_assign_to != "" && source.u_loc != "") { //Since is a not you need an && and not an ||

target.install_status = "1";
target.stockroom = "";
target.u_inuse = true;
}