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,...
Unanswered

JavaScript onSave / onLoad interaction with web request and Case creation problem

(0) ShareShare
ReportReport
Posted on by

Hi Dynamics community,

I've been tasked with doing some JavaScript development for a customer and I've run into a bit of a wall - I was hoping if I could get some assistance. The customer would like a web request to be pushed out when a Case object is created, and for another, different request to be pushed when a Case is closed. However, I've been running into an error or two and was hoping if I could get some more eyes on my code. At the moment, most of it is commented out, as I'm just testing the triggers, but I'm getting the error Required parameter is null or undefined: handler on load, even with this stripped-down code.

Currently, I have the onSave and onLoad functions tied to their respective triggers.

As for why this isn't a Workflow triggering On/After create, there's no way I could find to access a web resource / run JavaScript based on said Workflow - meaning we couldn't push a web request this way; if there is a way to do this, please let me know!

function caseOnLoad(){
	alert("On Load Change Handler Added");
	Xrm.Page.getAttribute("createdon").addOnChange(openCase());
}


function caseOnSave(){	
	alert("On Save");
	
	if(Xrm.page.getAttribute("statecode") == "Resolved" || Xrm.page.getAttribute("statecode") == "Cancelled"){
		closeCase();
	}
	return;
}

function openCase(){
    alert("Open Case");
	/*var myHeaders = new Headers();
	myHeaders.append("Content-Type", "application/xml");
	myHeaders.append("Accept", "application/xml");
	myHeaders.append("Authorization", "XXXXXXXXXXXXXXXXXXXX");

	var raw = '\r\n'  

	'\r\n'  	
		''   Xrm.page.getAttribute("customerid").getValue()   '\r\n'	
		''   Xrm.page.getAttribute("new_invoicenumber").getValue()   '\r\n'	
		''   Xrm.page.getAttribute("ticketnumber").getValue()   '\r\n'		
		''   Xrm.page.getAttribute("createdon").getValue()   '\r\n'	    
		''   TEST USER   '\r\n '   
	'';

	var requestOptions = {
		  method: 'POST',
		  headers: myHeaders,
		  body: raw,
		  redirect: 'follow'
		};

	fetch("XXXXXXXXXXXXXXXXXXXX", requestOptions)
		  .then(response => response.text())
		  .then(result => console.log(result))
		  .catch(error => console.log('error', error));*/
	return;
}

function closeCase(){
    alert("Close Case");
	/*var myHeaders = new Headers();
	myHeaders.append("Content-Type", "application/xml");
	myHeaders.append("Accept", "application/xml");
	myHeaders.append("Authorization", "XXXXXXXXXXXXXXXXXXXX");

	var raw = '\r\n'  	
	'\r\n'  
		''   Xrm.page.getAttribute("customerid").getValue()   '\r\n'  
		''   Xrm.page.getAttribute("new_invoicenumber").getValue()  '\r\n'  
		''   Xrm.page.getAttribute("ticketnumber").getValue()   '\r\n'  
		
	'';

	var requestOptions = {
		method: 'POST',
		headers: myHeaders,
		body: raw,
		redirect: 'follow'
	};

	fetch("XXXXXXXXXXXXXXXXXXXX", requestOptions)
		.then(response => response.text())
		.then(result => console.log(result))
		.catch(error => console.log('error', error));*/
	return;
}

I have the same question (0)

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 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans