How to copy one Reference Field Value into another

bammar
Kilo Sage
Kilo Sage

Hello All,

 

This seems so easy on the surface but I have been unable to copy one Reference Field to another ( even the Eureka Actions tab doesnt let you do this when creating a business rule).   I have one reference field ( Approval For)   that has a value in it. I can pull the value and even display it as message. However I can not populate this value into another reference field ( Change Number)     leaving me to have to type it in. Both fields reference the the Change task list,   I would love it if someone could show us very simply how to extract from field A and input into field B.   I know reference fields rely on things like Display Values and sys_ids. I have tried every combination of methods and tried using   getDisplayValue()); to get the original Value and   g_form.setValue to   as well as scowering the wiki /community . Thank you in Advance, there are many applications for why anyone would need to do this , this is just one of them.

 

 

BR - After, on insert or update of approval form

findChange();

 

function findChange() {

 

  var ri = new GlideRecord("sysapproval_approver");

 

    ri.get('sys_id', current.sysapproval);

 

//this does display the correct value when I save the form.

  gs.addInfoMessage(current.sysapproval.getDisplayValue());

 

// trying to get an acceptable value for which I can pass into set the   destination field , this is unsuccessfull

 

var change =   current.sysapproval.getDisplayValue();

   

            g_form.setValue( 'u_change', change);

 

 

}

1 ACCEPTED SOLUTION

Kalaiarasan Pus
Giga Sage

Why do you have 2 fields for same table?   Doesn't make sense to me



current.sysapproval.toString() // this will give sys id


current.sysapproval.getDisplayValue() will give.the display value of reference field. Number in this case


View solution in original post

15 REPLIES 15

Hi Salvador,



to make it even easier to answer- If i have two user reference fields Field A and Field B. Do you know the syntax of how to copy one field and put the value in the other.


Kalaiarasan Pus
Giga Sage

Why do you have 2 fields for same table?   Doesn't make sense to me



current.sysapproval.toString() // this will give sys id


current.sysapproval.getDisplayValue() will give.the display value of reference field. Number in this case


Hello,



Here is the dilemma. The approval emails do not allow us to bring in additional fields from the Change form- Approval for does reference the change but when you expand it it doesnt contain our customer change fields. . By adding a reference to change, i can go to the approval notification and fidn the change table expand that and integrate those fields.   But my question is more fundamental and simple than even that.   Suppose you wanted to copy user fields say - Automatically copy Caller to assigned to- how do you copy one reference field to another. what is the exact syntax   that I can use over and over again when i need to do this. Is it creating a New glide object ?


you can easily copy....but you cant use g_form in BR



inshead of this line


g_form.setValue( 'u_change', change);




use this




current.u_change = current.sysapproval;


-Anurag

just do this ..



create a before insert business rule on this table 'Approval [sysapproval_approver]'



condition : current.sysapproval.sys_class_name == 'change_request'



script:


current.u_change = current.sysapproval;