Last active
September 26, 2017 17:17
-
-
Save joerodgers/be22f7468a4303218d31c8c364a9e51f to your computer and use it in GitHub Desktop.
Post List Data to Remote Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
function PreSaveAction() // native sharepoint method for data validation | |
{ | |
if( $('input[title="Post to External Service"]')[0].checked ) | |
{ | |
var data = getData(); | |
console.log(data); | |
postToExternalService( 'https://remove-endpoint.azurewebsites.net/api/HttpTriggerCSharp1?code=dS4c3KUuxuAtdVIYOL4TcupqZhKRvAdtGMa/jn/765CkGLJso13jrB==', data ); | |
} | |
return true; | |
} | |
function getData() | |
{ | |
return { | |
"account_manager" : $("input[title='Account Manager']").val(), | |
"company_name" : $("input[title='Company Name Required Field']").val(), | |
"customer_contact" : $("input[title='Customer Contact Required Field']").val(), | |
"customer_title" : $("input[title='Customer Contact Title Required Field']").val(), | |
"customer_phone" : $("input[title='Customer Phone Number Required Field']").val(), | |
"customer_email" : $("input[title='Customer Email Address Required Field']").val(), | |
"notes" : $("textArea[title='Brief Description of Customer Opportunity']").val(), | |
"type_opportunity" : $("select[title='Type of Opportunity'] option:selected").text(), | |
}; | |
} | |
function postToExternalService( url, json ) | |
{ | |
$.ajax({ | |
type: 'POST', | |
url: url, | |
async: false, | |
beforeSend: function (xhr) { | |
xhr.setRequestHeader('data', JSON.stringify(json)); | |
}, | |
success: function (result, status, xhr) { | |
console.log('JSON data was posted successfully.'); | |
}, | |
error: function (xhr, status, error) { | |
console.log('JSON data failed to post. \n\tStatus: \'' + status + '\' \n\tError: \'' + error + '\''); | |
} | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment