Display the number of availability in stock ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 07:52 AM
Hello Expert !! I want a glideAjax Script to display the number of availability in stock ( like this exemple i have 2 Mask operationel ) ?
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 07:56 AM
Hello Hicham,
I provided response in your previous similar question I want display the number of availability in stock ( like this exemple i have 2 Mask operationel ) ?
Just wanted to check with you, if the my previous response in the above question resolved your issue. If yes, then please do close this thread/question by marking the appropriate response as correct.
If you still need any further help or guidance on this then please update those on this question.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 08:05 AM
Yes Please can you write again the script with the name of variables on the picture ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 10:41 AM
Hello Hicham,
You can write onChange Catalog Client script on field based on which you need to get the Available in Stock. For example if you are selecting any model in Hardware model variable and you need to get the Availability in Stock count for that Hardware model and stockroom, then you have to select Hardware model on your client script on field:
I am not sure the back-end back of you variable Availability in Stock please replace your variable name in place of u_available_count. Also replace other field/variable name accordingly
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.clearValue('u_avalible_count'); // Clear value if newValue == ""
return;
}
if (newValue) {
var getAvaCnt = new GlideAjax('GetAvailableStockUtils');
getAvaCnt.addParam('sysparm_name', 'getAvailabilityOfStock');
getAvaCnt.addParam('sysparm_clinic_equipment', newValue);
getAvaCnt.addParam('sysparm_categorie', g_form.getValue('categorie'));
getAvaCnt.addParam('sysparm_life_cycle_stage', g_form.getValue('life_cycle_stage'));
getAvaCnt.getXMLAnswer(modAvaCount);
} else {
g_form.clearValue('u_avalible_count');
}
}
function modAvaCount(response) {
var answer = response;
g_form.setValue('u_avalible_count', answer);
}
Write a script include with client callable is set to true and can use code something like below:
var GetAvailableStockUtils = Class.create();
GetAvailableStockUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAvailabilityOfStock: function() {
var availableCount = 0;
var hardwareModel = this.getParameter('sysparm_clinic_equipment');
var Categorie = this.getParameter('sysparm_categorie');
var LifeCycleStage = this.getParameter('sysparm_life_cycle_stage');
var stkCount = new GlideAggregate('sn_hcls_clinic_equipment');
stkCount.addEncodedQuery('u_life_cycle_stage=' + LifeCycleStage + '^u_categorie=' + Categorie);
stkCount.addAggregate('COUNT', 'u_name'); // check back end name of your [Name] field and change if required
stkCount.query();
if (stkCount.next()) {
availableCount = agg.getAggregate('COUNT', 'u_name'); // check back end name of your [Name] field and change if required
}
return availableCount;
}
type: 'GetAvailableStockUtils'
});
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 06:56 PM
Hello Hicham,
Initially I misunderstood your requirement. You can use the below code:
You can write onChange Catalog Client script on materiel_type field based on which you need to get the Available in Stock.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.clearValue('availability_in_stock'); // Clear value if newValue == ""
return;
}
if (newValue) {
var getAvaCnt = new GlideAjax('GetAvailableStockUtils');
getAvaCnt.addParam('sysparm_name', 'getAvailabilityOfStock');
getAvaCnt.addParam('sysparm_materiel_type', newValue);
getAvaCnt.getXMLAnswer(modAvaCount);
} else {
g_form.clearValue('availability_in_stock');
}
}
function modAvaCount(response) {
var answer = response;
g_form.setValue('availability_in_stock', answer);
}
Write a script include with client callable is set to true and can use the below script include code:
var GetAvailableStockUtils = Class.create();
GetAvailableStockUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAvailabilityOfStock: function() {
var availableCount = 0;
var MaterielType = this.getParameter('sysparm_materiel_type');
var clinicEquipment = new GlideRecord('sn_hcls_clinic_equipment');
if (clinicEquipment.get(MaterielType)) {
availableCount = clinicEquipment.getValue('u_quantity'); // check back end name of your [Name] field and change if required
}
return availableCount;
}
type: 'GetAvailableStockUtils'
});
Please mark my respsone as helpful/correct, if it answer your question.
Thanks