- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 07:32 AM
So i have this requirement that i am not able to figure out
i have this catalog item request for.
What i need is, when a user logs into the form, it will detect their location
and base on their location i need to search for the title Managing Partner and have that user auto fill the reference field
i was thinking of a on change client script but not quiet sure on how to script it out for that
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 08:04 AM - edited 10-18-2023 08:58 AM
Hello @Peter Williams ,
You can use GlideAjax to get the managing Partner.
Use the below code in on change client script:-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getManagingPartner');
ga.addParam('sysparm_name', 'getMP');
ga.addParam('sysparm_lawyer', newValue); //newValue will look up field for
ga.getXML(callback);
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('managing_partner', answer);
}
}
Create a script include named 'getManagingPartner' and make it client callable.
Use the below script in the script include:-
var getManagingPartner = Class.create();
getManagingPartner.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getMP: function() {
var loc;
var lawyer = this.getParameter('sysparm_lawyer');
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", lawyer);
gr.query();
if (gr.next()) {
loc = gr.location.toString();
}
var mp = new GlideRecord('sys_user');
mp.addQuery('location',loc);
mp.addEncodedQuery('titleLIKEManaging Partner');
mp.query();
if(mp.next()){
return mp.sys_id.toString();
}
},
type: 'getManagingPartner'
});
If this response clears up your doubt, kindly flag it as both helpful and correct.
Thanks,
Alka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 08:10 AM
Where would i add in the second script to?
Create a script include named 'getManagingPartner' and make it client callable.
Not sure where to put that too
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 08:17 AM
Search in navigator:
Click on new to create script include:
Name :-getManagingPartner
Check the client callable checkbox
and paste the code in script
Thanks,
Alka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 08:26 AM
This populates but wrong person
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 08:29 AM
There might be multiple person for lawyer location and title as managing partner and it's selecting 1 st one because of if condition. Can you recheck any other condition we can add to get the correct user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 08:42 AM
look like a spelling mistake in the code
mp.addQuery('loaction',loc);