Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Why are my functions not being found on the form?

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
};

	

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Why are my functions not being found on the form?

    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/

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Why are my functions not being found on the form?

    Hi Dominic Pilione,

    Did you try the solution in this thread?

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

  • Dominic Pilione Profile Picture
    Dominic Pilione 90 on at
    RE: Why are my functions not being found on the form?

    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

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans