- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 06:54 AM
Hi All,
We've a requirement, let's a there is an alm_asset record opened in form view. This has two reference fields 'Account' (customer_account) and Location (cmn_location). Now, if I open the look up of location field and click on 'New' to create a new location record, I need 'Account' field (reference) in that new location to be auto field with the Asset's location.
Is there a way to achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 01:17 PM
Try replacing all occurrences of this.opener with self.opener
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 07:40 AM
Hi Shiladitya,
Once you go to the cmn_location you may be too late. What you can do is try using a UI Action (Add Location or something like that). In the scripting, you can create the new record, populate the account and then open that record via setRedirectURL. Here's an example of what the code might look like:
function doCreateProblem() {
var mySysID = current.update;
var location = new GlideRecord("cmn_location");
var sysID;
location.setValue("u_account", current.customer_account.getDisplayValue());
// add any other values that can be preset
sysID = location.insert();
mySysID = current.update();
action.setRedirectURL(location);
action.setReturnURL(current);
}
This is a simplified version of a UI Action that I have running on our instanaces. Please let me know if you have any further questions.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 07:46 AM
HI @Shiladitya Das ,
I trust you are doing fine.
You can use a UI policy to automatically set the value of the 'Account' field in the Location record when a new Location record is created from the Asset's form view.
To implement this, you need to follow these steps:
- Navigate to the 'Location' table and create a new UI policy.
- Set the 'Action' field of the policy to 'Run script'.
- In the 'Advanced' section of the policy, add the following script:
- Set the 'Applies on' field of the policy to 'Insert'.
- Set the 'Run scripts' field of the policy to 'Client'.
// get the current asset record
var asset = g_form.getUniqueValue();
// get the value of the account field in the asset record
var account = g_form.getValue('customer_account');
// set the value of the account field in the location record
g_form.setValue('account', account);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 10:53 AM
Hi @Amit Gujarathi,
Thanks for the responding. I've tried the following but still not working.
Am I missing something here?
UI Policy:
Table = cmn_location
Global = True
Onload = True
Run script = True
Script: Execute if true -
function onCondition() {
// get the current asset record
var asset = g_form.getUniqueValue();
// get the value of the account field in the asset record
var account = g_form.getValue('customer_account');
// set the value of the account field in the location record
g_form.s
etValue('account', account);
}
Screenshots:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 11:42 AM - edited 05-02-2023 11:45 AM
The parent window object can be accessed via this.opener from the reference popup. Create an onLoad client script for Location table with the following code:
if (this.opener && this.opener.g_form)
g_form.setValue('account', this.opener.g_form.getValue('customer_account'));
You could also add another condition to make sure it only works if the popup was opened from an alm_asset form:
if (this.opener && this.opener.g_form && this.opener.g_form.getTableName() == 'alm_asset')
g_form.setValue('account', this.opener.g_form.getValue('customer_account'));
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/