How to change variable value if URL GET parameters changes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2024 12:23 AM
If a id_logiciel parameter is provided in GET in the URL, if a logiciel matches this model number, it must be pre-selected, in the variable logiciel/extension/application( mandatory, changeable, type lookup set box from table logiciel and get value field ID & class
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2024 04:46 AM
write onLoad client script
function getUrlParameter(name) {
var regex = new RegExp('[?&]' + name + '=([^&]*)');
var results = regex.exec(window.location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}
// Get the id_logiciel parameter from the URL
var idLogiciel = getUrlParameter('id_logiciel');
if (idLogiciel) {
// Create a GlideAjax object to call a Script Include
var ga = new GlideAjax('GetLogicielRecord');
ga.addParam('sys_id', idLogiciel);
ga.getXMLAnswer(function(response) {
var record = JSON.parse(response);
if (record && record.sys_id) {
// Set the lookup field value
g_form.setValue('logiciel', record.sys_id);
}
});
}
SCRIPT INCLUDE SAMPLE:
var GetLogicielRecord = Class.create();
GetLogicielRecord.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRecord: function() {
var sysId = this.getParameter('sys_id');
var gr = new GlideRecord('logiciel');
if (gr.get(sysId)) {
// Return the record in JSON format
return JSON.stringify({
sys_id: gr.sys_id.toString(),
// Include other fields as needed
});
}
return JSON.stringify({});
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2024 05:13 AM
Hi @Mani A thanks for you're answer I scripted the client script part like this to get the url params id_logiciel :
function onLoad() {
//Type appropriate comment here, and begin script below
var url = top.location.href;
var value = new URLSearchParams(url).get('id_logiciel');
if (value) {
g_form.setValue('var_application_logiciel_extention_list_2', value);
}
}
And in the script includes I did this but im not sure if its correct :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2024 08:35 AM
but you are requirement is get URL data and check it in different table , if matches then prefill it..
so don't setValue directly in variable directly ..call script include and do validation in your lookup tbl and return value to client side and set it.. please check my sample code and replace it with correct table, field names
please mark my answer as correct/helpful if you are ok with it