Prepopulate Reference Field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 10:14 AM
Hello All --
I know this is possible but I'm drawing a complete blank. I'm trying to establish a reference field link between two tables so that data from one
table can be displayed on the other. I'm trying to configure it so that the reference field is populating on its own without needing to manually
type anything in.
Here's my set up
Number is my autonumbered record. Approval History is a reference to a second table where I store the Number plus the fields I have showing under the green arrow.
The structure of that table is like this:
I am trying to populate the Approval History field to prepopulate so the field information shows on its own.
I have tried both a client script and business rule to populate the field with no luck. In both cases, I used code like this:
var id = current.sys_id;
current.u_approval_history = id;
current.update();
To no avail.
I would appreciate other ideas on how to do this.
Thanks!
Chris
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 11:09 AM
Here is my understanding of what you are trying to perform
1) You have a table ABC (with number) which has a reference field to "Approval History" table. On the same table ABC, you have configured the section with name "Apprval History" which has some fields like manager approval, Technician completion etc. The same fields are also there on your "Approval History" table as well which you want to populate on table ABC.
You can do it via both client script as well as business rules.
For client script, you will have to initialize the AJAX call and bring in those field values from approval history table in JSON format and then will have to parse those further to put their value on fields like Manager approval etc on table ABC.
Other method via Business rule would be to write down the onBefore update / insert BR which will fire when "Approval Histroy" field value changes.
In your code you can write down something
current.u_manager_approval = current.u_approval_history.u_manager_approval / it says put the manager approval field value from Approval History record to Manager approval field on table ABC (with number field).
You can extend the same logic to populate other fields as well.
Now this is all about how we can do it.
Next question is, why do you require it????
ServiceNow has provided the icon next to magnifying glass symbol on reference field. Person require to see the details can click on it and see those details?
What requirement you are dealing with?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 11:28 AM
Deepak -
Almost but not quite.
The Approval History section are all fields from my Approval History table, separate from my main requests table.
Every click of an "approval" button I have in the app records the person logged in and the date/time to the request's record in Approvals History table.
My requirement is to display on the original record all date/times and users that are recorded for each request so viewers can see the history of the request without needing to mouse over anything.
And to be clear, It DOES work when I go into the Approval History field and click through on the request number.
What I want to do though, is to NOT have to do that. I want the request number to be populated in the reference field so that the fields under Approval History are already populated when the record loads.