Code issue
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 08:18 AM
hello team,
the below code is not working for me . The code is to change the sub-category based on the category selection.
Can u help me find the errors
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(g_form.getValue("id")=='category')
{
if(newValue=='hardware')
g_form.setValue("subcategory","laptop");
else if(newValue=='software')
g_form.setValue("subcategory","OS");
else if(newValue=='')
{
g_form.showFieldMsg("subcategory","please fill vaue of category","info",true);
var y = new Date();
g_form.setValue('opened_at',y);
g_form.setValue('caller_id', g_user.userName());
return false;
}
}
}
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2024 11:34 PM
Hi @keepitsimpl ,
Here is the corrected version of your script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
function formatDateTime(date) {
var year = date.getFullYear();
var month = ('0' + (date.getMonth() + 1)).slice(-2);
var day = ('0' + date.getDate()).slice(-2);
var hours = ('0' + date.getHours()).slice(-2);
var minutes = ('0' + date.getMinutes()).slice(-2);
var seconds = ('0' + date.getSeconds()).slice(-2);
var formattedDate = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
return formattedDate;
}
if (g_form.getValue("id") == 'category') {
if (newValue == 'hardware')
g_form.setValue("subcategory", "laptop");
else if (newValue == 'software')
g_form.setValue("subcategory", "OS");
else if (newValue == '') {
g_form.showFieldMsg("subcategory", "please fill vaue of category", "info", true);
var y = new Date();
g_form.setValue('opened_at', formatDateTime(new Date()));
g_form.setValue('caller_id', g_user.userName());
}
}
}
If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.
Thanks,
Amitoj Wadhera