- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 11:47 PM
Hi Team,
I have created variable's in catalogs
1 start date - Date and time type variable
2 required time - Duration type variable
3 End time - String type.
I need to add the duration and date and time variables. And populate the end time in string
Can you please help me requriment.
Thank you
Siva
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 06:03 AM - edited 07-08-2024 06:27 AM
Hi @Community Alums,
Check the below link, it may be of any help for you.
https://www.servicenow.com/community/now-platform-forum/add-duration-to-date-time/m-p/1153814
Try below script and check:
onChange Client Script (start date), make sure the duration is first selected and then the start date.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var gaChng = new GlideAjax('Test'); //script include name
gaChng.addParam('sysparm_name', 'getEndDate'); //second parameter - function name in the SI
gaChng.addParam('sysparm_date', newValue);
gaChng.addParam('sysparm_duration', g_form.getValue('u_duration'));
gaChng.getXML(getData2);
function getData2(response) {
var answer2 = response.responseXML.documentElement.getAttribute('answer');
if (answer2) {
g_form.setValue('end_date', answer2);
}
}
}
Script Include (client callable checkbox - true):
var Test = Class.create();
Test.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getEndDate: function() {
try {
var gdt = new GlideDateTime(this.getParameter('sysparm_date'));
var dur = new GlideDuration(this.getParameter('sysparm_duration'));
gdt.add(dur);
return gdt.getValue();
} catch (ex) {
gs.info('Error:' + ex.string() + '\nLine:' + ex.lineNumber);
}
},
type: 'Test'
});
Mark the response correct and helpful if the answer assisted your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 06:09 AM
Something like this should work.
Add pass the fields to line 1 and 2
var gdt = new GlideDateTime('pass fiueld value');
var dur = new GlideDuration(<pass field value>);
//dur.setValue('1970-01-02 00:00:00');
gdt.add(dur);
gs.info(gdt.getDisplayValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 12:03 AM
Hi @Community Alums,
please check below link:
Thank you, please make helpful if you accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 12:53 AM
Hi @Yashsvi ,
Thank you for quick response,
I am tried below script. But not worling
Script inculde
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 02:47 AM
Hi @Community Alums
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 05:28 AM
Hi @Dr Atul G- LNG ,
Thank you for your response.
I tried below client script its getting null value
Script include:
Can you please check my code .