Conditional mandatory field

Riya17
Giga Contributor

Hi,

I have to make 'justification' mandatory if the 'planned_start_time' is less than 3 hours from the change is requested.  I've tried with business rule, it didn't work.  What is the best way to achieve this.

 

Thanks

Riya

1 ACCEPTED SOLUTION

Same code on form load and Planed Date change

 

Thanks

View solution in original post

22 REPLIES 22

Below is Script Include

 

var GetDateDifference = Class.create();
GetDateDifference.prototype = Object.extendsObject(AbstractAjaxProcessor, {

hours:function(){
var start=new GlideDateTime(this.getParameter('sysparm_start'));
var end=new GlideDateTime(this.getParameter('sysparm_end'));

var sec=gs.dateDiff(start.getDisplayValue(),end.getDisplayValue(),true);
gs.log('getDisplayValueInternal():'+sec);
var hr=(sec/3600);
return hr;
},
type: 'GetDateDifference'
});

Hi Upender,

Is the below code a UI policy?

2. Call on form load and Planed Date change

var end=g_form.getValue('u_planned_start_time');
var start=g_form.getValue('opened_at');
var answer;
var ga=new GlideAjax('GetDateDifference');
ga.addParam('sysparm_name','hours');
ga.addParam('sysparm_start',start);
ga.addParam('sysparm_end',end);
ga.getXMLWait();
answer=ga.getAnswer();
if(answer<3)
g_form.setMandatory('u_justification',true);

 

Thank you

Riya

Same code on form load and Planed Date change

 

Thanks

Hi,

If your requirement is fulfilled please close this thread.

 

Thanks