Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Unanswered

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

Posted on by Microsoft Employee

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

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans