Creating outage record: Begin and End dates get cleared as I move cursor out of the duration fields

nameisnani
Mega Sage

Hi Team , 

 

can anyone please help me with the below issue .

 

Creating outage record: Begin and End dates get cleared as I move cursor out of the duration fields. This heavily affects productivity.

Are the duration fields supposed to be entered/calculated manually?
Why are begin & end date values being cleared automatically as you move cursor OUT of any of the duration fields? Is this as designed, and any rationale behind this?

 

 

nameisnani_0-1736998075199.png

nameisnani_1-1736998114795.png

 

 

can anyone please provide me the fix for this ,

 

why this error comes please help me here .

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@nameisnani 

check this

Setting the Outage Duration field clears the Begin and End dates 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@nameisnani 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@nameisnani 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

MackI
Kilo Sage

hi @nameisnani 

 

As per the KB Knowledge document -- this is a Baseline Clinet Script which cause this so you need to modify it (My suggestion first copy it and then do the modifications on your test instance)

 
 
Locate the Client Script:

Go to System Definition > Client Scripts in your ServiceNow instance.
In the "Table" column, filter for cmdb_ci_outage.
In the "Field name" column, filter for or browse to find entries related to duration or look at scripts with onChange type.
 
Modification (Recommended)  Understand the Intent: Before making changes, try to understand the original purpose of the code that clears the fields. Was there a specific reason for it? Is it needed in some scenarios but not others?
Conditional Logic: Modify the script to include conditional logic (if statements) so that the clearing of begin and end only happens when it's actually required.
 
A sample script would be--- 
 

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    // Only clear begin and end if a certain condition is NOT met
    if (!someConditionWhereBeginAndEndShouldBeKept) { // Replace with your actual condition
        g_form.clearValue('begin');
        g_form.clearValue('end');
    }

    // ... rest of your script ...
}

 

 

 
 
For example:

 where we need to add logic for someConditionWhereBeginAndEndShouldBeKept. The logic will check whether begin and end date should be cleared or not. 
Example: If the fields should only be cleared when the outage type is "Planned," you could add a condition like: if (g_form.getValue('type') != 'Planned') { ... }
 
 
If you like this opinion and your problem is resolved after reviewing and applying it. Please kindly mark this your best answer ‌(Accepted) 🌠‌ OR  mark it  Helpful ‌‌ if you think that you get some insight from this content relevant to your problem and help me to contribute more to this community
MackI | ServiceNow Technical Consultant | DXC Technology Australia | ServiceNow Practice | LinkedIn Top IT Operation Voice 2023 | Sydney,Australia