Attach a note to a lead within dynamics crm 2011 - dynamics-crm

I am using Microsoft Dynamics CRM 2011 and I need to create an Annotation and attach it to a Lead within JavaScript. At the moment I have an object similar to:
var note = new Object();
note.subject = "some text";
note.notetext = "some other text";
But, I am unsure as to how define the link between the Annotation and a Lead. On a related note, when it comes to committing the these entities I would "POST" them using the OData services?
Thanks
EDIT #1: Using the info from Jason's post I've now got the following code, but it doesn't appear to be adding a node. Can someone point out where I'm going wrong?
var note = new Object();
note.subject = "Test Note";
note.notetext = "some test text";
note.objectid = { id: selectedItemId, logicalname: "lead", name: "A Name" };
var postRequest = new XMLHttpRequest();
postRequest.open( "POST", url + "/LeadSet(guid'" + selectedItemId.toString() + "')", true );
postRequest.setRequestHeader( "Accept", "application/json" );
postRequest.setRequestHeader( "Content-Type", "application/json;charset=utf-8" );
postRequest.setRequestHeader( "X-HTTP-Method", "MERGE" );
postRequest.onreadystatechange = function() {
if( this.readyState == 4 )
{
var text = "complete";
}
};
postRequest.send(note.toString());
The "selectedItemId" is a GUID passed into the function. When the "readystate" field is set to 4 the containing "status" is set to 400.
EDIT #2: I have tried passing in the following string and I still get a 400 (Bad Request) response.
{ObjectTypeCode: 4, Subject: \"test note\", NoteText: \"text\", ObjectId: { ObjectIdTypeCode: 4, Id: \"" + selectedItemId + "\", LogicalName: \"lead\", Name: \"A Name\" } }
EDIT #3: OK, so if I remove the "X-HTTP-METHOD" line, wrap the "ObjectTypeCode" number 4 in quotes and remove the "ObjectIdTypeCode", then I get a 500 (Internal Error) and a code of "-2147217150".

You can create the reference like this:
note.Subject = "TEST";
note.NoteText = "123";
note.ObjectId = { Id: "8343E0C3-76C9-E111-A3BC-000C29336979", LogicalName: "lead", Name: "test lead" };

Related

Logic Apps- Unable to Set To and From fields For Dynamics 365 Email Entity

I am trying to create an email entity in Dynamics 365 using Logic Apps.
I am filling in the From and Recipient fields but the when I check the record created in Dynamics, I see that these fields are empty. I know that to and from fields are activity parties in Dynamics 365 email entity. Do we have a sample json which I can use in Logic Apps to create an Email Activity with To and From fields set?
As per the product group its not available right now to create and set to and from fields of email entity from logic apps
Sorry, answering without access to laptop. And this is not straightforward answer for you. But just a start to build your own request Json object.
Replace your record guids in below snippet & execute this in browser console or CRM js web resource. Take the JSON.stringify(email) at the end & that's what you're looking for.
var serverURL = Xrm.Page.context.getClientUrl();
var email = {};
email["subject"] = "Email Subject";
email["description"] = "email body description";
email["regardingobjectid_contact#odata.bind"] = "/contacts(guid1)";
//activityparty collection
var activityparties = [];
//from party
var from = {};
from["partyid_systemuser#odata.bind"] = "/systemusers(guid2)";
from["participationtypemask"] = 1;
//to party
var to = {};
to["partyid_contact#odata.bind"] = "/contacts(guid3)";
to["participationtypemask"] = 2;
activityparties.push(to);
activityparties.push(from);
//set to and from to email
email["email_activity_parties"] = activityparties;
var req = new XMLHttpRequest();
req.open("POST", serverURL + "/api/data/v8.0/emails", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Prefer", "return=representation");
req.onreadystatechange = function() {
if (this.readyState == 4 /* complete */ ) {
req.onreadystatechange = null;
if (this.status == 201) {
var emailUri = this.getResponseHeader("OData-EntityId");
}
else {
var error = JSON.parse(this.response).error;
alert(error.message);
}
}
};
req.send(JSON.stringify(email));
}
In case if you need it, Code referred from this blog.

React/Redux download file

I need to download a file from the server when a button is clicked.
I created a MaterialUI button and on its onclick callback i call an action of the container component connected.
The action is asynchronous and does an ajax POST:
export const onXlsxClick = () => dispatch => {
const urlParams = {
filters: {
aggregation: 'macro_area',
chart_resolution: '1_hour',
chart_from: '1478080363',
chart_to: '1477993963'
},
labels: ['PROVA1', 'PROVA2'],
series: [
{
label: null,
timestamp: 1478080363,
values: [123, 345]
},
{
label: null,
timestamp: 1477993963,
values: [153, 3435]
}
]
};
return $.ajax({
url:'/rest/export/chart/xlsx',
type: 'POST',
dataType: 'application/json',
contentType: 'application/json',
data: JSON.stringify(urlParams)
})
.done(data => {
console.log('success');
})
.fail(error => {
console.log(error);
});
};
The server receive the request and handle it correctly through this REST service:
#POST
#Path("xlsx")
#Produces("application/vnd.ms-excel")
public Response getXlsx(ChartExportRequest request) {
ResponseBuilder responseBuilder;
ChartExportRequestDTO reqDto = null;
try {
reqDto = parseDTO(request);
checkRequestDTO(reqDto);
ExportDTO dto = getXlsxProvider().create(reqDto);
responseBuilder = Response.ok(dto.getFile())
.header("Content-disposition", "attachment;filename=" + dto.getFileName());
}
catch(Exception e) {
logger.error("Error providing export xlsx for tab RIGEDI with request [" + (reqDto != null ? reqDto.toString() : null) + "]", e);
responseBuilder = Response.serverError().entity(e.getMessage());
}
return responseBuilder.build();
}
The problem is that the response arrives correctly to the client but then nothing happens: I am expecting that the browser shows the download dialog (example: in chrome I expect the bottom bar of downloads to appear with my file).
What am I doing wrong?
AS per Nate's answer here, the response of Ajax request is not recognised by a browser as a file. It will behave in the same way for all Ajax responses.
You need to trigger the download popup manually.
In my implementation, I used filesaverjs to trigger the download popup, once I have received the API response in reducer.
Since FileSaver uses blob for saving the file, I am sending the response from server as a blob, converting it into string array buffer and then using it to save my file. This approach was described in
Please find the sample code below for the reducer :
(using reducer for state modification, as per Redux)
reducer.js
let fileSaver = require("file-saver");
export default function projectReducer(state = {}, action)
{
let project;
switch (action.type) {
case GET_PROJECT_SUCCESS :
project = Object.assign(action.response.data);
return project;
case EXPORT_AND_DOWNLOAD_DATA_SUCCESS :
let data = s2ab(action.response.data);
fileSaver.saveAs(new Blob([data], {type: "application/octet-stream"}), "test.xlsx");
return state;
}
return state;
}
function s2ab(s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i = 0; i != s.length; ++i) {
view[i] = s.charCodeAt(i) & 0xFF;
}
return buf;
}

Opening Main form instead of Quick create form - CRM

I have function that should open Quote Quick Create Form from account, but it opens Quote Main Form. What should i change to open Quick Create Form?
var thisAccount = {
entityType: "account",
id: Xrm.Page.data.entity.getId()
};
var callback = function (obj) {
console.log("Created new " + obj.savedEntityReference.entityType + " named '" + obj.savedEntityReference.name + "' with id:" + obj.savedEntityReference.id);
}
var setName = { name: "Quote made by " + Xrm.Page.getAttribute("name").getValue() };
Xrm.Utility.openQuickCreate("quote", thisAccount, setName).then(callback, function (error) {
console.log(error.message);
});
As discovered by Milos, the quick create form must be activated.

How to passing array values from ajax to spring xml controller

I am creating survey page which has the following ajax to pass answer values
if(check==0)
{
var surveyVal="";
var len=answers.length;
for(i=0;i<=len-1;i++)
{
if(i!=len-1)
surveyVal+="val"+i+"="+answers[i]+"&";
else
surveyVal+="val"+i+"="+answers[i];
}
var ajaxUrl = "survey.do";
var data = surveyVal;
alert(data);
var returnValue = false;
tinymce.util.XHR.send({
url : ajaxUrl,
content_type : "application/x-www-form-urlencoded",
type : "POST",
data : {values: data.toString() },
success : function(data) {
alert("Done! Content Saved")
// Do anything you need to do if save successful
ed.setProgressState(false); // cancel showing progress
},
error : function( type, req, o ){
alert("Save Failed\n Error: " + type + "\n HTTP Status: " + req.status);
}
});
//the alert gives
val0=0,val1=2
etc as per the options I have chosen at the browser . how can I take these val to my controller as it is so that I can capture in logs and save in my database as individual answers . (please note I cant use annotation)
currently controller is like this which is not working
String val0 = request.getParameter("val0");
String val1 = request.getParameter("val1");
String val2 = request.getParameter("val2");
String val3 = request.getParameter("val3");
String val4 = request.getParameter("val4");
logger.info + "|"+ToolsUser.getPlatform()
+ ">Update Survey Inputs"
+ "|Answers:"
+ "|Answer-1:"+val0
+ "|Answer-2:"+val1
+ "|Answer-3:"+val2
+ "|Answer-4:"+val3
+ "|Answer-5:"+val4
);
thanks in advance
can you replace this line
data : {values: data.toString() },
with this
data : "values=" data.toString(),
and in your controller try to get the value of
request.getParameter("values");
and let me know if this worked for you

POST method in Google Apps Script

May I ask what is wrong when I use the POST method in the Apps script?
function myFunctionpost() {
var url = "mydomain.com/2spreadsheet.php";
var data = { "testpost" : " Text text text" };
var payload = JSON.stringify(data);
var headers = { "Accept":"application/json",
"contentType" : "application/json",
"Authorization":"Basic _authcode_"
};
var options = { "method":"POST",
"contentType" : "application/json",
"headers": headers,
"payload" : payload
};
var response = UrlFetchApp.fetch(url ,options);
Logger.log(response );
}
The myFunctionpost() in the Apps script is about posting the Json data : "testpost" to the url.
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo "Server is requested";
if(isset($_POST["testpost"])){
echo "Post something here";
echo $_POST["testpost"];
}
}
And the code in (2spreadsheet.php) showing that I want to post the data I posted, but it does not work.
The Loggin Output:
[15-07-12 14:06:00:205 HKT]
Server is requested
Can anyone tell me what is the problem?
You don't have to specify the content type and can leave out JSON.Stringify. Your object data is already a JavaScript object. It will be interpreted as an HTML form.
var url = "mydomain.com/2spreadsheet.php";
var data = { "testpost" : " Text text text" };
var options = { "method":"POST",
"payload" : data
};
var response = UrlFetchApp.fetch(url ,options);
Logger.log(response );
The content type will default to application/x-www-form-urlencoded. You can check this with $_SERVER["CONTENT_TYPE"].

Resources