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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Why are my functions not being found on the form?

(0) ShareShare
ReportReport
Posted on by 90

Hi all,

I am practicing writing JS functions on forms, and I can't seem to resolve this error. I have added a few functions to my web resource, all which worked previously. But now that I am adding the notification function to this form, it's breaking all of the other functions above which previously worked? I added my code to to a syntax checker and it all checked out as well. Any ideas?

if (typeof (Dom) == "undefined") { Dom = { __namespace: true }; }
if (typeof (Dom.Scripts) == "undefined") { Dom.Scripts = { __namespace: true }; }
if (typeof (Dom.Scripts.Opportunity) == "undefined") { Dom.Scripts.Opportunity = { __namespace: true }; }


Dom.Scripts.Opportunity.Form = {
	OnLoad: function (executionContext) {
		debugger
		if (executionContext == null)
			return;
		var formContext = executionContext.getFormContext();
		Dom.Scripts.Opportunity.Form.opportunityFormTesting(executionContext);
		Dom.Scripts.Opportunity.Form.HideOpportunitySummary(executionContext);
	},
	opportunityFormTesting: function (executionContext) {
		debugger
		if (executionContext == null)
			return;
		var formContext = executionContext.getFormContext();
		var optionSetTemperature = formContext.getControl("dom_temperature");
		//var optionSetChoice = optionSetLabelName.getAttribute();

		//var optionSetChoice = formContext.getControl("dom_temperature").getAttribute().getValue();		
		var optionSetChoice = formContext.getAttribute("dom_temperature").getValue();

		//if (optionSetChoice == null) {
		//return;
		if (optionSetChoice == (179820000)) {//Celsius
			optionSetTemperature.setLabel("Celsius");//Approach 1

			//formContext.getControl("dom_temperature").setLabel("Celsius");//Approach 2

		}
		else if (optionSetChoice == (179820001)) {//F

		}

	},
	HideOpportunitySummary: function (executionContext) {
		debugger
		if (executionContext == null)
			return;
		var formContext = executionContext.getFormContext();
		var tabObj = formContext.ui.tabs.get("Summary");
		var sectionObj = tabObj.sections.get("Opportunity_details");
		var optionSetChoice = formContext.getAttribute("dom_hideopportunitysummary").getValue();

		if (optionSetChoice == (179820000)) {
			sectionObj.setVisible(false);
		}
		else if (optionSetChoice == (179820001)) {
			sectionObj.setVisible(true);
		}
		
	},
	addOpportunityNameRecommendation: function (executionContext) {
		debugger
		if (executionContext == null)
			return;
		var formContext = executionContext.getFormcontext();
		var myControl = formContext.getControl("name");
		var oppName = formContext.data.entity.attributes.get("name");
		var specialChar = /[^\w\s]/g;
		var searchedString = oppName.search(specialChar);

		if (searchedString == -1)
			return;

		else if (myControl.addNotification({
			messages: 'Are you sure you would like to include special characters on this opportunity name?',
			notificationLevel: 'RECOMMENDATION',
			uniqueId: 'my_unique_id'
		})
		}
	},
	__namespace: true
};

	

I have the same question (0)
  • Dominic Pilione Profile Picture
    90 on at

    The addOpportunityNameRecommendation function on the bottom is the one that isn't working and is causing all of the functions above to break. Here is the error code:

    One of the scripts for this record has caused an error. For more details, download the log file.

    Web resource method does not exist: Dom.Scripts.Opportunity.Form.OnLoad
     
    I get this error code for each function on the form that I try to initiate
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Dominic Pilione,

    Did you try the solution in this thread?

    community.dynamics.com/.../web-resource-not-found

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    There is a syntax error in your JS code.

    Please use below tool to validate your JS code.

    esprima.org/.../validate.html

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 81 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans