- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2016 09:19 AM
On our incident form we have the company and caller fields:
If a user clicks the reference icon:
And then clicks the new button:
I would like to have the company field auto populated based on the company selected in the incident.
I have considered modifying the onclick of the reference picker so it inserts the sys id of the company into the url of the reference picker popup as a sysparm. Then using a client script on the sys_ref_list view of the user form to retrieve the sys id from the referring url. However, this involves dom manipulation in order to replace the onclick which I would like to avoid. Also we have a number of other similar situations in our system and the same would need to be implemented for all of them.
I was thinking there has to be a simpler way to achieve this but was unable to find a solution online. Does anybody have a better idea?
Thanks,
Matt
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2016 09:51 AM
Okay so i've implemented this solution in a test system and it seems to be working nicely. I've posted it here for the benefit of others and for some constructive criticism.
1) Set the the the value of "Dependant" in the dictionary record of the user field on the incident form to "company".
2) Create the following client script on the user table:
Type: onLoad
Global: false
View: sys_ref_list
// Set the company from sysparm_dependent of the referrer if it's a new record and the view is sys_ref_list
// author: matt a
function onLoad() {
if (g_form.isNewRecord() && typeof document !== 'undefined' && 'referrer' in document) {
var referrer = document.referrer.toString();
var i = referrer.indexOf('sysparm_dependent=');
if (i !== -1) {
var sysid = referrer.substr(i + 18, 32);
if (/^[a-f0-9]{32}$/i.test(sysid)) {
g_form.setValue('company', sysid);
g_form.setReadOnly('company', true);
}
}
}
}
This should work for any similarly related fields on other tables. I will actually be using this on account and contact tables within our prod instance. The use of the company and user was just an example to illustrate my issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2016 01:29 AM
Thanks Goran. That's a pretty good idea. I guess my only concern with this is that it might promote the creation of more records since it would be so easy to create a new one users may do it before looking properly. Also generally people will have already opened the reference popup to find the user so is only one click from that box to create the new one.
I really would like to achive this using the default system new button if possible. I'm pretty sure my original suggestion would work but it would be nice to achieve it without having to replace the default onclick of the ref picker.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2016 07:54 AM
Building on Goran's response, I think if you construct a reference qualifier for Caller where the company selected is passed to the reference query then you could leverage that from the New button click if the filters follow through the new button click, then you just need an onLoad to populate the field on the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2016 09:21 AM
This got me really excited. I thought this was going to be the simple solution I was after. I just tried it in a test instance though and sadly I couldn't get it to work. However, when looking into this I think I might have stumbled across the solution I was looking for. Thanks very much Andres and Goran for steering me in the right direction.
I found that if I set company as dependent in the dictionary entry for the user field its value is passed as sysparm_dependent to the reference popup which is then passed inturn to the new user form in the referring url. I can now just create an on load script which runs on the sys_ref_list view of the user form to retrieve and set the value. No messing with the DOM needed Also I should be able to easily apply this elsewhere by simple setting the dependant field on the appropriate dictionary entry and the form onload script should handle the rest.
I guess i'm using sysparm_dependent for a purpose it wasn't intended for. Can anyone think of any situations where this solution might cause problems?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2016 09:51 AM
Okay so i've implemented this solution in a test system and it seems to be working nicely. I've posted it here for the benefit of others and for some constructive criticism.
1) Set the the the value of "Dependant" in the dictionary record of the user field on the incident form to "company".
2) Create the following client script on the user table:
Type: onLoad
Global: false
View: sys_ref_list
// Set the company from sysparm_dependent of the referrer if it's a new record and the view is sys_ref_list
// author: matt a
function onLoad() {
if (g_form.isNewRecord() && typeof document !== 'undefined' && 'referrer' in document) {
var referrer = document.referrer.toString();
var i = referrer.indexOf('sysparm_dependent=');
if (i !== -1) {
var sysid = referrer.substr(i + 18, 32);
if (/^[a-f0-9]{32}$/i.test(sysid)) {
g_form.setValue('company', sysid);
g_form.setReadOnly('company', true);
}
}
}
}
This should work for any similarly related fields on other tables. I will actually be using this on account and contact tables within our prod instance. The use of the company and user was just an example to illustrate my issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 09:42 AM
is there any way to do this without using the sysparm_dependent. i just want to carry over another reference field other than company. i.e. account.