Retrieve Campaigns Microsoft Dynamic CRM 3.0 - dynamics-crm

does anybody knows how to get (programmatically - C#) the list (and details) of campaigns on Microsoft CRM 3.0 (using the webservice CRM Service) ??
Any help or documentation link would be appreciated.
Thanks in advance.

If somebody is interested, I found out how to get campaigns from Microsoft CRM 3.0 using the webservice. Here is the code.
fetchFilter += #"<fetch mapping='logical'>";
fetchFilter += #"<entity name='campaign'><all-attributes/>";
fetchFilter += #"<link-entity name='systemuser' to='owninguser'>";
fetchFilter += #"<filter type='and'>";
fetchFilter += #"<condition attribute='firstname' operator='eq' value='" + firstName + "' />";
fetchFilter += #"<condition attribute='lastname' operator='eq' value='" + lastName + "' />";
fetchFilter += #"</filter>";
fetchFilter += #"</link-entity>";
fetchFilter += #"</entity>";
fetchFilter += #"</fetch>";
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(CrmWebService.Fetch(fetchFilter));
Hope it will be useful for somebody.
Bye.

Related

Dynamic field validation message issue

1.I have added dynamic array field which changes on the dropdown. and I have added "required" in html
$.each(data.result, function (key, value) {
if (typeof value['filter'] !== "undefined") {
var id = value['filter']['id'];
var name = value['filter']['name'];
$(".label_filter2").append('<div class="form-group m-form__group"><label class="custom_form_label">' + name + '<span class="error_msg">*</span></label><input type="text" class="form-control m-input m-input--air filter_specification" name="filter[' + id + ']" placeholder="Enter ' + name + '" data-toggle="m-tooltip" required title="' + name + '"></div>');
}
});
2.Its totally work, but problem is validation message same like label.
https://www.screencast.com/t/Hqawm0Tae
3.I need "this field is require" message.I hope you are understand my question.Please help me.

How to apply custom FetchXML to a Subgrid using JavaScript

The implementation of applying custom FetchXML to a Subgrid appears to have changed from CRM 2011/13 to Dynamics 365. The change is with respect to GridControl.SetParameter().
I have followed many articles talking about this same issue but nothing is working at the moment on Dynamics 365 Online.
Is there any alternative method to achieve the same functionality?
In my below code, I am trying to fetch all of the phone call and email activities related to the account and show them on the Subgrid which is on the account form.
//Shows only the PhoneCall activities related to Organisation
//var allPhoneCallsGrid = window.parent.document.getElementById("AllPhoneCalls"); //Not supported by Microsoft
//var allPhoneCallsGrid = document.getElementById("AllPhoneCalls"); //Not Supported by Microsoft
var allPhoneCallsGrid = Xrm.Page.getControl("AllPhoneCallactivities"); //Sub-grid is on the Account Form
if (allPhoneCallsGrid == null) {
setTimeout(function() {
AccountForm.AccountFormOnLoad();
}, 2000); //if the grid hasn’t loaded run this again when it has
return;
}
var accountId = Xrm.Page.data.entity.getId();
var allPhoneCallsfetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
" <entity name='activitypointer'>" +
" <attribute name='activitytypecode' />" +
" <attribute name='subject' />" +
" <attribute name='ownerid' />" +
" <attribute name='prioritycode' />" +
" <attribute name='regardingobjectid' />" +
" <attribute name='activityid' />" +
" <attribute name='scheduledstart' />" +
" <attribute name='scheduledend' />" +
" <attribute name='statecode' /> " +
" <attribute name='community' /> " +
" <order attribute='modifiedon' descending='false' />" +
" <filter type='and'>" +
" <condition attribute='activitytypecode' operator='ne' value='4206' />" +
" <condition attribute='activitytypecode' operator='eq' value='4210' />" +
" </filter>" +
" <link-entity name='incident' from='incidentid' to='regardingobjectid' alias='ad'>" +
" <filter type='and'>" +
" <condition attribute='account' operator='eq' uitype='account' value='" + accountId + "' />" +
" </filter>" +
" </link-entity>" +
" </entity>" +
"</fetch>";
allPhoneCallsGrid.control.SetParameter("fetchXml", allPhoneCallsfetchXml); //Unable to get property 'SetParameter' of undefined or null reference
//allPhoneCallsGrid.getGrid().setParameter("fetchXml", allPhoneCallsfetchXml);
allPhoneCallsGrid.control.Refresh(); //refresh the sub grid using the new fetch xml
Using Xrm page object, we can bind JavaScript to the onload event of the subgrid.
JavaScript can be bind to the subgrid using Ribbon Workbench tool.
For sample code, on how to write JavaScript on subgrid event, please refer this link
http://www.inogic.com/blog/2015/11/identify-the-trigger-for-an-on-load-event-for-sub-grid-in-dynamics-crm/
Community thread advised against this unsupported approach. Recommendation is to use RetrieveMultiple pre-operation plugin to intercept the call & pass our custom fetchxml query to achieve the result.
This is also having its own disadvantage, because of performance degradation by costly pre-event call & have to limit the exact retrieval call. But this is atleast in supported area.
Script on load form:
var control = Xrm.Page.getControl("Your Subgrid control");
var grid = control.getGrid();
var fetchXml = "<fetch version='1.0' output-format='xml-platform'
mapping='logical' distinct='false'>...</fetch>" //Your fetch Xml
grid.setParameter("fetchXML", fetchXml);

JQuery Function Calling On Click Of Anchor Tag Inside Kendo Grid MVC

I created a column inside my kendo grid in mvc as follows with a anchor tags based on true or false of a field.
columns.Bound(c => c.IsMapped).Width(140).ClientTemplate(
"# if (IsMapped == true) { #" +
"<a href='DeleteMap?Id=#=Id#' class='btn btn-xs default'>UnMap </a>" +
"# } else { #" +
"<a onclick=\"Show(this);\" href='javascript:void(0);'
class='btn btn-xs default'> Map </a>" +
"# } #" );
The first anchor tag is working fine and invoking my controller action. But the second anchor tag is not invoking the java script function. My Java script function is as follows.
function Show(e) {
e.preventDefault();
alert('Test1');
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var wnd = $("#portal").data("kendoWindow");
wnd.refresh({
url: "Test",
data: { id: dataItem.Id, pvid: dataItem.PVId }
});
wnd.center().open();
};
when I look in the page source, the second anchor tag is rendered as follows that has no onclick attribute set.
<a class="k-grid-filter" href="javascript:void(0)"><span class="k-icon k-
filter"></span></a>
Anything wrong in my code? Thanks in advance
Personally this is what I would do for your template to make it easier to maintain and test.
Restructure your current template from the nested JavaScript in your razor code and pull it out into a separate function like so:
columns.Bound(c => c.IsMapped).Width(140).ClientTemplate("#=unMap(data)#");
then create the associated function:
function unMap(data){
var retString = '';
if(data.IsMapped === true) {
retString = 'UnMap ';
}
else {
retString = '<a data-map="'+ data.Id + '" href="#" class="btn btn-xs default"> Map </a>';
}
return retString;
}
then in the events config for the grid add this:
.Events(events => events.DataBound("onBoundData"))
then attach this JavaScript function:
function onBoundData(e) {
$("a[data-map]").on("click", function (me) {
me.preventDefault();
//do your Show(this) method in here
});
}
this will then bind the event to the links with the data-map attribute.
Hope this helps and if you have any follow up questions feel free to ask.
Instead of building anchor tag like this
onclick=\"Show(this);\"
change it to
onclick='Show(this);'
the following code worked for me. Here I am assigning a css class to anchor element and handling click event of anchor element using jquery based on css class.
#Html.ActionLink("UnMap", "DeleteMap", new { Id = #item.Id })
</text>).ClientTemplate(
"# if (IsMapped == true) " + #"{# <a href=""DeleteMap?
Id=#=Id#"">UnMap</a>" + "# } " +
#"else {# <a href=""\#"" class='myCommand'>Map</a>" + "# } #").Width(75);
Thats working for me
cshtml
columns.Bound(c => c.REQUESTNUMBER).Title("Request ID").ClientTemplate("#=urlMap(data)#").Width(140);
js
var urlMap = function(obj){
return "" + obj.REQUESTNUMBER + "";
}

Why controllers action doesn't send json data in response

I learn ASP.NET MVC and have some issue.
I create two links by ajax helper method in view. They send mailsType argument and response json data. Here is the code of links and AjaxOptions object
<div class="list-group" style = "text-align: center; margin-top: 10px;">
#Ajax.ActionLink("Incoming", "GetMails", new { mailsType = State.Incoming }, opts,
new{#class = "list-group-item active", data_type = "Incoming"})
#Ajax.ActionLink("Outgoing", "GetMails", new {mailsType = State.Outgoing}, opts,
new { #class = "list-group-item", data_type = "Outgoing" })
</div>
Here is ajaxoption, using in ajax helpers
AjaxOptions opts = new AjaxOptions
{
OnSuccess = "viewMail",
};
I handle response by javascript function
function viewMail(data) {
var html =
'<table class="table table-hover table-striped">' +
'<thead>' +
'<tr><th>' + (data.State == 'Incoming' ? 'From' : 'To') + '</th> <th>Subject</th> <th>Date</th></tr>' +
'</thead>' +
'<tbody>';
$(data.Mails).each(function(i, el) {
html += '<tr><td>' + el.From + '</td> <td>' + el.Subject + '</td> <td>' + el.Date + '</td></tr>';
});
html += '</tbody></table>';
$('#contentDiv').html(html);
}
And here is code of action method in controller
public ActionResult GetMails(State mailsType)
{
if (Request.IsAjaxRequest())
{
return Json(new
{
State = Enum.GetName(typeof (State), mailsType),
Mails = _serviceManager.GetMessages(mailsType)
}, "application/json", JsonRequestBehavior.AllowGet);
}
else
{
ViewBag.State = Enum.GetName(typeof(State), mailsType);
return PartialView(_serviceManager.GetMessages(mailsType));
}
}
When I use second link all works good, but when I use first one, i have internal server error with code 500 and response type is text/html.
I use this links to return partialviews and they all works before.
I tried to use my own ajax request, but result was still the same. I can't understand what's wrong. I understan't that question is abstract, but may be you had same problem or know why it happens.
Edit1
When I write address from link in address bar, I have this error:
System.InvalidOperationException: Timeouts are not supported on this stream.
I tryed set big timeout in ajax request, but it didn't help. Reqest executes successfuly when I send less data in response.
I think it related with size of data sending in response. Am I wrong? What reasons of this error can be?
I will by happy all yours advice. Thanks to all!

Spring dojo request issue

I am quite new to Spring framework and i have a problem.
I have a page A.jsp and in this page i have a link to page B.jsp
<c:url value="${pageContext.request.contextPath}" var="contextPath" />
Click here
And in controller
#RequestMapping("pageB")
public String pageBlink(SitePreference sitePreference, Device device, Model model) {
return "pageB";
}
Now on page B.jsp i want to invoke an Ajax call.
I have a link Send request
function myFunction(){
dojo.xhrGet({
// The URL of the request
url: "requestPage",
method: "POST",
handleAs: "json",
// The success callback with result from server
load: function(jsonData) {
var content = "";
dojo.forEach(jsonData.newsItems,function(locationPoint) {
// Build data from the JSON
content += "<p>" + locationPoint.name + "</p>";
content += "<p>" + locationPoint.latitude + "</p>";
content += "<p>" + locationPoint.longitude + "</p>";
content += "<p>" + locationPoint.number + "</p>";
});
},
// The error handler
error: function() {
// Do nothing -- keep old content there
},
// generate an extra GET variable to prevent browsers from caching
preventCache: true
});
}
And add into controller
#RequestMapping(value="requestPage", method = RequestMethod.GET)
public MyObj returnEVSELocations(){
logger.log(Level.INFO, "return evse locations --------------");
MyObj myObj = new MyObj();
// add some stuff into the obj
return myObj;
}
But this request a requestPage.jps ... i want just to work in my page (B.jsp).
Any help is more than welcome.
Thanks!
I found the issue.
In fact there was 2 problems
1. In Ajax call i must have
dojo.forEach(jsonData, ...) instead dojo.forEach(jsonData.newsItems, ...)
2. In the controller in on my method i must add the annotation
public #ResponseBody MyObj
I hope this help someone to front the same issue.

Resources