web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

OnSave error - Jscript

(0) ShareShare
ReportReport
Posted on by 35

Howdi,

I have a web resource set up that is meant to total 10 fields and check it against another, if they do not match a warning appears.  I have this working on CRM 2011 but cannot get it to work in CRM 2013.  Field names have changed and I have triple checked and got someone else to check they are correct in the code.

Code is as follows:

function calculate(ExecutionObj) {

var val1 = Xrm.Page.getAttribute(new_fld1).getValue();
var val2 = Xrm.Page.getAttribute(new_fld2).getValue();
var val3 = Xrm.Page.getAttribute(new_fld3).getValue();
var val4 = Xrm.Page.getAttribute(new_fld4).getValue();
var val5 = Xrm.Page.getAttribute(new_fld5).getValue();
var val6 = Xrm.Page.getAttribute(new_fld6).getValue();
var val7 = Xrm.Page.getAttribute(new_fld7).getValue();
var val8 = Xrm.Page.getAttribute(new_fld8).getValue();
var val9 = Xrm.Page.getAttribute(new_ld9).getValue();
var val10 = Xrm.Page.getAttribute(new_fld10).getValue();
var val11 = Xrm.Page.getAttribute(new_Hosting).getValue();

var total = 0;
if (val1 != undefined && val1) total += val1;
if (val2 != undefined && val2) total += val2;
if (val3 != undefined && val3) total += val3;
if (val4 != undefined && val4) total += val4;
if (val5 != undefined && val5) total += val5;
if (val6 != undefined && val6) total += val6;
if (val7 != undefined && val7) total += val7;
if (val8 != undefined && val8) total += val8;
if (val9 != undefined && val9) total += val9;
if (val10 != undefined && val10) total += val10;
if (val11 != undefined && val11) total += val11;

var orderTotal = Xrm.Page.getAttribute(new_total).getValue();

if (orderTotal != total) {
alert('Forecast does not equal Total Order, please amend');
ExecutionObj.getEventArgs().preventDefault();

}

}

I have it set to execute 'onsave' along with a script that stops the auto save on modify/30secs (which works) but when I save I get an error:

Field: CRM Form

Event: onsave

Error: new_fld1 is undefined

I have tried field names with proper capitalisation as in the schema name and all lower case.  I have tried adding ' ' around the Schema names in the code too.

So basically is my code correct? Or can you offer any other guidance.

Thanks

*This post is locked for comments

I have the same question (0)
  • SavageDLX Profile Picture
    35 on at

    Thanks, annoyingly that was one of my previous versions but i had spelt the mixed up the prefix 'new_'.

    Cheers

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Varsha deshpande Profile Picture

Varsha deshpande 5

#2
JS-09031509-0 Profile Picture

JS-09031509-0 3

#3
Ciprian  P Profile Picture

Ciprian P 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans