- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2021 03:31 AM
Hi Team,
I have added the script include and need to call based on certain conditions and set its value on the client-side.
Client Script : OnChange()
FieldName: Last Full test date
script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue) {
//Type appropriate comment here, and begin script below
var is_testing_reqd = g_form.getValue('u_pen_test_last_full_test_date');
var last_full_testdate = g_form.getValue('u_is_testing_required');
var app_id = g_form.getValue('u_pen_test_app_name');
var ga = new GlideAjax('ExpComplianceCheckLastFullTest'); //Name of the Script Include
ga.addParam('sysparm_name', 'ChckComplStatus'); //Name of the function in the script include
ga.addParam('sysparm_app_id', app_id); //Parameter to pass to the script include
ga.addParam('sysparm_date', last_full_testdate); //Parameter to pass to the script include
ga.getXML(ExpComplianceCheckLastFullTestParse);
}
}
//Function that gets the response and will return to the client. You can place your alert in this function
function ExpComplianceCheckLastFullTestParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if ((answer == 'true2') && (newValue == 'Yes')) {
g_form.setValue('u_pen_test_manual_test_status', '2'); // complaint
}
if ((answer == 'true5') && (newValue == 'Yes')) {
g_form.setValue('u_pen_test_manual_test_status', '5'); // overdue
}
if ((answer == 'true4') && (newValue == 'Yes')) {
g_form.setValue('u_pen_test_manual_test_status', '4'); // never tested
}
if ((answer == 'true') && (newValue == 'No')) {
g_form.setValue('u_pen_test_manual_test_status', '1'); // no tested required
}
if (answer == 'true3') {
g_form.setValue('u_pen_test_manual_test_status', '3'); // deviation
}
}
Script Include :
var ExpComplianceCheckLastFullTest = Class.create();
ExpComplianceCheckLastFullTest.prototype = Object.extendsObject(AbstractAjaxProcessor, {
// type: 'ExpComplianceCheckLastFullTest'
ChckComplStatus: function() {
var appid = this.getParameter('app_id');
var fulltest = this.getParameter('last_full_testdate'); //Passing the start date from the client
var start = new GlideDateTime();
var end = new GlideDateTime('fulltest');
var duration = GlideDateTime.subtract(end, start);
var totaldate = duration.getNumericValue() / 86400000; // convert milliseconds to days
totaldate = parseInt(totaldate);
var dev = new GlideRecord('u_pen_test_deviations');
dev.addQuery('u_pen_test_deviation_app_id', appid);
dev.query();
if (dev.next()) {
var pen_test_deviations = dev.u_pen_test_deviations.getDisplayValue();
var pen_test_no_record = false;
//gs.log("***DEBUG: pen_test_deviations and pen_test_no_record" + pen_test_deviations + pen_test_no_record);
} else {
pen_test_no_record = true;
//gs.log("***DEBUG: pen_test_deviations and pen_test_no_record found" + pen_test_no_record);
}
if (pen_test_deviations == 'Y') {
// current.u_is_testing_required = 'No';
//current.u_pen_test_manual_test_status = 3; // deviation
return true3;
}
if (((pen_test_deviations == 'N') || (pen_test_no_record == true)) && (totaldate < 365)) {
//complaint
return true2;
}
if (((pen_test_deviations == 'N') || (pen_test_no_record == true)) && (totaldate > 365)) {
// overdue
return true5;
}
if ((pen_test_deviations == 'N') || (pen_test_no_record == true) && (fulltest == '')) {
// never tested
return true4;
}
if ((pen_test_deviations == 'N') || (pen_test_no_record == true)) {
// no testing required
return true;
}
}
});
but the above script is not working.
could you please help with this?
your effort is really appreciated.
Thank you,
Abhishek Kumar
Solved! Go to Solution.
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2021 03:59 AM
Hi
another problem I can recognize is
if ((answer == 'true2') && (newValue == 'Yes')) {
g_form.setValue('u_pen_test_manual_test_status', '2'); // complaint
}
Variable newValue is unknown there because the function ExpComplianceCheckLastFullTestParse is declared outside of onChange.
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2021 03:37 AM
Hi
code lines like
return true5
are wrong because in that way the JavaScript interpreter expects a variable of that name.
Correct text-based return values have to be wrapped with quotation marks
return "true5"
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2021 03:50 AM
Hi,
The above code is still not working even I have added in the double quotation("").
it should update the field's value whenever the last full test date is changed but not working.
Thank you
Abhishek Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2021 03:59 AM
Hi
another problem I can recognize is
if ((answer == 'true2') && (newValue == 'Yes')) {
g_form.setValue('u_pen_test_manual_test_status', '2'); // complaint
}
Variable newValue is unknown there because the function ExpComplianceCheckLastFullTestParse is declared outside of onChange.
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2021 08:48 PM
Hi
Did my reply answer your question?
If so, please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
If not, please tell me what you are still missing!
Kind regards
Maik