Run workflow from ribbon button - dynamics-crm

I was trying to run a workflow from ribbon button in grid:
function TriggerWorkflow(entityId, workflowGuid)
{
debugger;
/*Generate Soap Body.*/
var soapBody = "<soap:Body>" +
" <Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
" <Request xsi:type=\'ExecuteWorkflowRequest\'>" +
" <EntityId>" + entityId + "</EntityId>" +
" <WorkflowId>" + workflowGuid + "</WorkflowId>" +
" </Request>" +
" </Execute>" +
"</soap:Body>";
/*Wrap the Soap Body in a soap:Envelope.*/
var soapXml = "<soap:Envelope " +
" xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' " +
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
GenerateAuthenticationHeader() +
soapBody +
"</soap:Envelope>";
/* Create the XMLHTTP object for the execute method.*/
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.open("POST", "/MSCRMservices/2007/crmservice.asmx", false);
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");
/* Send the XMLHTTP object. */
xmlhttp.send(soapXml);
}
But it did throw an exception:
GenerateAuthenticationHeader() is undefined

Instead of using the GenerateAuthenticationHeader(), try using the following code:
var context = GetGlobalContext();
var header = context.getAuthenticationHeader();
Or if it doesn't work, create the authentication header manually
<soap:Header>
<CrmAuthenticationToken xmlns="http://schemas.microsoft.com/crm/2007/WebServices">
<AuthenticationType xmlns="http://schemas.microsoft.com/crm/2007/CoreTypes">
0
</AuthenticationType>
<OrganizationName xmlns="http://schemas.microsoft.com/crm/2007/CoreTypes">
AdventureWorksCycle
</OrganizationName>
<CallerId xmlns="http://schemas.microsoft.com/crm/2007/CoreTypes">
00000000-0000-0000-0000-000000000000
</CallerId>
</CrmAuthenticationToken>
</soap:Header>

Related

Error on Edit Post shows 422 (Unprocessable Entity) in Ajax call

I keep getting a 422(Unprocessable Entity) error, how do I fix this?
The below is my code on ajax call, can someone help me on to fix this problem?
$(document).on('click', '.edit-post', function() {
$('.edit-modal').css('display','block');
$('.posts-table').css('display','none');
var id = $(this).attr('data-id');
var title = $(this).attr('data-title');
var slug = $(this).attr('data-slug');
var category = $(this).attr('data-category');
var featured_image = $(this).attr('data-image');
var body = $(this).attr('data-body');
$('#edit-post-form #edit-title').val(title);
$('#edit-post-form #edit-slug').val(slug);
$('#edit-post-form #edit-category').val(category);
//$('#edit-post-form #edit-image').val(featured_image);
$('#edit-post-form #edit-body').val(body);
$('#edit-id').val($(this).data('id'));
});
//Update New Post
$("#update-post").click(function(e) {
e.preventDefault();
id = $('#edit-id').val();
var title = $('#edit-post-form #edit-title').val();
var slug = $('#edit-post-form #edit-slug').val();
var category_id = $('#edit-post-form #edit-category').val();
var featured_image = $('#edit-post-form #edit-image').val();
var body = $('#edit-post-form #edit-body').val();
var form = new FormData();
form.append('title', title);
form.append('slug', slug);
form.append('category_id', category_id);
form.append('featured_image', featured_image);
form.append('body', body);
$.ajax({
type:'PUT',
url: "/updatepost/" + id,
headers: {
'X-CSRF-TOKEN' : $('input[name="_token"]').val()
},
dataType: 'json',
cache: false,
contentType: false,
processData: false,
data: form,
success: function(data) {
toastr.success('Successfully Updated Post!', 'Success Alert', {timeOut: 5000});
$('#'+ id).html("<tr id='" + data.id + "' class='item'><th>" + data.id + "</th><td>" + data.title + "</td><td>" + data.body + "</td><td>" + data.created_at + "</td><td><button class='edit-modal btn btn-info' data-id='" + data.id + "' data-title='" + data.title + "' data-slug='" + data.slug + "' data-category='" + data.category_id + "' data-image='" + data.featured_image + "' data-body='" + data.body + "'><span class='glyphicon glyphicon-edit'></span> Edit</button></td></tr>");
$('.edit-modal').css('display','none');
$('.posts-table').css('display','block');
}
});
});
The data of the post will show in the edit form, but when I try to submit it after editing some fields, 422 Unprocessable entity keeps showing.

My jquery and ajax call is not responding and showing unexpected error in console

I don't know why my code is giving error while making the ajax call and not responding or working at all. I ran this on an html file. I took this function - getParameterByName() from another stackoverflow answer.tweet-container tag is down the code below outside this script and an empty division.I tried some jquery also.
<script>
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
$(document).ready(function(){
console.log("working");
var query = getParameterByName("q")
// console.log("query");
var tweetList = [];
function parseTweets(){
if (tweetList == 0){
$("#tweet-container").text("No tweets currently found.")
} else {
//tweets are existing, so parse and display them
$.each(parseTweets, function(key, value){
//console.log(key)
// console.log(value.user)
// console.log(value.content)
var tweetKey = value.key;
var tweetUser = value.user;
var tweetContent = value.content;
$("#tweet-container").append(
"<div class=\"media\"><div class=\"media-body\">" + tweetContent + "</br> via " + tweetUser.username + " | " + View + "</div></div><hr/>"
)
})
}
}
$.ajax({
url:"/api/tweet/",
data:{
"q": query
},
method: "GET",
success:function(data){
//console.log(data)
tweetList = data
parseTweets()
},
error:
function(data){
console.log("error")
console.log(data)
}
})
});
</script>
strong text
Fix the quotes to resolve your syntax error:
$("#tweet-container").append("<div class=\"media\"><div class=\"media-body\">" + tweetContent + " </br> via " + tweetUser.username + " | " + "View</div></div><hr/>")

symfony3 chat application using gos socketBundle

i'm developping a chat application using gos socketBundle i'm trying to show connected users using this code in javascript .
when the subscribe is done to the channel connected users always connectedUsers are null?? could any one help me please ?
{{ ws_client()}}
<script type="text/javascript">
var websocket = WS.connect("ws://127.0.0.1:8080");
//var websocket = WS.connect("ws://{#{{ wsUrl }}#})");
websocket.on("socket/connect", function (session) {
session.subscribe("connected-users/channel", function (uri, payload) {
console.log(session);
console.log(payload);
var connectedUsers = JSON.parse(payload.connectedUsers);
var newtml = '';
connectedUsers.forEach(function (user) {
newtml += '<a name="toggle" class="connectedUserLink" onclick="talkToUser(\'' + user.id + '\', \'' + user.username + '\')">' + user.username + '</a>';
});
$('#connectedUserNbr').html(connectedUsers.length);
$('#connectedUserList').html(newtml);
});
});
websocket.on("socket/disconnect", function (error) {
//error provides us with some insight into the disconnection: error.reason and error.code
console.log("Disconnected for " + error.reason + " with code " + error.code);
});
</script>

jquery selectin a input in a div

I have the following code to call a ajax POST :
$("a[href=Save]").click(function() {
var thisform = $(this).attr("name");
// Get all the information left in the form
var lname = $('div[name="' + thisform + '"] input[name="lname"]').val();
var fname = $('div[name="' + thisform + '"] input[name="fname"]').val();
var mname = $('div[name="' + thisform + '"] input[name="mname"]').val();
var language = $('div[name="' + thisform + '"] input[name="lang"]').val();
var title = $('div[name="' + thisform + '"] input[name="title"]').val();
var ptype = $('div[name="' + thisform + '"] input[name="ProfileType"]').val();
var vip = $('div[name="' + thisform + '"] input[name="VIP"]').val();
var vreason = $('div[name="' + thisform + '"] input[name="Vreason"]').val();
alert (lname);
//Set the Ajax Request
$.post("..\ajax\profileMod.php", {
'lname':lname,
'fname':fname,
'mname':mname,
'language':language,
'title':title,
'ptype':ptype,
'vip':vip,
'vreason':vreason
};
.done(function(data) {
// php code : echo json_encode(array("name"=>"Called!"));
alert(data.name);
});
// Stop original behavior
return false;
});
I don't know where I went wrong but the code is not working. I'm trying to call a php file using the POST, and showing a message to see if the file got called correctly. All my "var" are getting to right value (I've tested all of them one by one).
I've look at so many post to find the error that my eyes hurt! So I'm asking help!!!
Thank you!
looks like you put a ";" where you should have put a ")"
'vip':vip,
'vreason':vreason
}; <-- problem
.done(function(data) {
// php code : echo json_encode(array("name"=>"Called!"));
alert(data.name);
Should be
'vip':vip,
'vreason':vreason
}) <-- fix
.done(function(data) {
// php code : echo json_encode(array("name"=>"Called!"));
alert(data.name);
i think

passing parameters containing # in URL for calling webservice using AJAX

I am calling one of my webservice in which im sending some paramters like key,id,subject line,etc
example:
http://asv.msdasmafetrix.net/public/mobile.ashx?method=getparsedtemplate_contactinfo&emailbody='" + emailbody + "'&subjectline='" + subjectline + "'&contactemailid=" + contactemailid + "&id=" + jasondata.id + "&key=" + jasondata.key
but,in parameters like subject and emailbody # variable is present due to which it is breaking my code.and giving me undefined value.i have even tried encodeURI.got no success though.
my code is:
var uri="http://asv.msdasmafetrix.net/public/mobile.ashx?method=getparsedtemplate_contactinfo&emailbody='" + emailbody + "'&subjectline='" + subjectline + "'&contactemailid=" + contactemailid + "&id=" + jasondata.id + "&key=" + jasondata.key";
$.ajax({
type: "GET",
url: encodeURI(uri),
success: function(msg) {
jasondata = eval('(' + msg + ')');
var subjectline = jasondata.subjectline;
alert(subjectline);
}
});
any help ...!!
Try using encodeURIComponent(uri)
Documentation for encodeURIComponent

Resources