Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

OnSave error - Jscript

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

  • SavageDLX Profile Picture
    SavageDLX 35 on at
    RE: OnSave error - Jscript

    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans