Transform script not working properly.

ashish9
Tera Contributor

I have a field from which I am trying to push a value to target table but it is not working see screenshot.

1 ACCEPTED SOLUTION

Did you try writing this script in directly in field map? or do you have one already?

If not, can you create one

Can you check in syslog table, if you are getting any error as part of it, also put gs.info to check what is the final value that you are getting, for a string value, I dont think there should be that much of issue

 

Best Regards
Aman Kumar

View solution in original post

11 REPLIES 11

Allen Andreas
Administrator
Administrator

Hi,

In the future, please paste the actual script using the forum feature: "Insert/Edit Code sample":

Or at the very least, paste the screenshot within your post and not as an attachment. We help hundreds of people on the forums and having us download a file, then the file being of script, isn't ideal.

With the above said, I've always had to lookup the record using GlideRecord. Such as:

var gr = new GlideRecord('table_name');
gr.get(target.sys_id);
gr.setValue('middle_name', secondName);
gr.update();

So this would be placed after your var secondName declaration. Replace table_name with the actual table_name

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thank You Allen for your suggestion. It make sense. Will check and get back to you.

ashish9
Tera Contributor

Thanks Allen, It worked,

 

Just curious why below code didn't worked why we need to Glide target table

 

var string = source.u_dn;
var secondPart = string.split(',')[2];
var equalPosition = secondPart.search('=');
var secondName = secondPart.substring(equalPosition + 1, 100);
target.middle_name = secondName;

Hi,

I see you had my reply marked as Correct and now it's not.

But it works, and it worked for you?

You have to use GlideRecord in an onAfter to access the record and then set the value.

You can choose to use it wherever you want in transform script itself (this is ran before the record is fully transformed), in onAfter (which is done after the row is transformed), etc. it doesn't really matter and it's your preference.

I'd recommend reviewing what I've posted above and use that.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!