- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I Have built a client script to pre populate some fields when opening a new normal change. It is working perfectly in global view but it is not working when opening the change in the SOW. I have UI type as All and is an onLoad script Any advice current script below:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
so what debugging did you do?
did you try adding alert and see?
did you see browser console any error?
may be window.location is not working in SOW, remove that
try this once
function onLoad() {
// 1. Ensure it is a brand new record
if (!g_form.isNewRecord()) {
return;
}
// 2. Isolate to Normal changes only
if (g_form.getValue('type') !== 'normal') {
return;
}
// 3. Detect "Copy Change" by checking if planning fields already have values
var implBlank = (g_form.getValue('implementation_plan') === '');
var backBlank = (g_form.getValue('backout_plan') === '');
var testBlank = (g_form.getValue('test_plan') === '');
var justBlank = (g_form.getValue('justification') === '');
var riskBlank = (g_form.getValue('risk_impact_analysis') === '');
var commsBlank = (g_form.getValue('u_communications_plan') === '');
// If any of the key planning fields are already populated, assume this is a copy
var isCopy = !(implBlank && backBlank && testBlank && justBlank && riskBlank && commsBlank);
// 4. Execute prepopulation ONLY if it's a true, fresh, empty Normal change
if (!isCopy && implBlank && backBlank && testBlank) {
g_form.setValue('implementation_plan', 'Steps to implement the Change and people / teams involved at each stage:Checkpoints and Go/No-go decision points: (For more complex Changes a more detailed plan can be attached)');
g_form.setValue('backout_plan', 'Steps to backout the Change, restore service, and/or contingency plans if Change unsuccessful:How you would know that a backout is required:How long it would take?: Has this backout / contingency plan been done before?:');
g_form.setValue('test_plan', 'Pre-implementation testing (attach test evidence): Post-implementation testing:');
g_form.setValue('justification', 'Why the Change is necessary: The potential consequences if the Change is not made:.');
g_form.setValue('risk_impact_analysis', 'Risks and any potential impact for users during or after the Change:Potential downstream impacts:');
g_form.setValue('u_communications_plan', 'Who will be notified?, when? and who by?:');
g_form.setValue('short_description', 'What will be done and what will it be done to?');
g_form.setValue('description', 'A description of the work and any relevant background needed');
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
so what debugging did you do?
did you try adding alert and see?
did you see browser console any error?
may be window.location is not working in SOW, remove that
try this once
function onLoad() {
// 1. Ensure it is a brand new record
if (!g_form.isNewRecord()) {
return;
}
// 2. Isolate to Normal changes only
if (g_form.getValue('type') !== 'normal') {
return;
}
// 3. Detect "Copy Change" by checking if planning fields already have values
var implBlank = (g_form.getValue('implementation_plan') === '');
var backBlank = (g_form.getValue('backout_plan') === '');
var testBlank = (g_form.getValue('test_plan') === '');
var justBlank = (g_form.getValue('justification') === '');
var riskBlank = (g_form.getValue('risk_impact_analysis') === '');
var commsBlank = (g_form.getValue('u_communications_plan') === '');
// If any of the key planning fields are already populated, assume this is a copy
var isCopy = !(implBlank && backBlank && testBlank && justBlank && riskBlank && commsBlank);
// 4. Execute prepopulation ONLY if it's a true, fresh, empty Normal change
if (!isCopy && implBlank && backBlank && testBlank) {
g_form.setValue('implementation_plan', 'Steps to implement the Change and people / teams involved at each stage:Checkpoints and Go/No-go decision points: (For more complex Changes a more detailed plan can be attached)');
g_form.setValue('backout_plan', 'Steps to backout the Change, restore service, and/or contingency plans if Change unsuccessful:How you would know that a backout is required:How long it would take?: Has this backout / contingency plan been done before?:');
g_form.setValue('test_plan', 'Pre-implementation testing (attach test evidence): Post-implementation testing:');
g_form.setValue('justification', 'Why the Change is necessary: The potential consequences if the Change is not made:.');
g_form.setValue('risk_impact_analysis', 'Risks and any potential impact for users during or after the Change:Potential downstream impacts:');
g_form.setValue('u_communications_plan', 'Who will be notified?, when? and who by?:');
g_form.setValue('short_description', 'What will be done and what will it be done to?');
g_form.setValue('description', 'A description of the work and any relevant background needed');
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Thanks Ankur, Perfect