selected Picklist value not saving in dynamic CRM? - dynamics-crm

I have added javascript for reverse the items in the picklist (rating) to the opportunity entity. It is done. but when I am filling the data and saving it, it is not saving the selected item from the rating picklist to the database. What do I have to do?
var oField = crmForm.all.opportunityratingcode;
var items = oField.options.length;
var arrTexts = new Array(items);
var arrValues = new Array(items);
for(i=0;i<items;i++)
{
arrTexts[i]=oField.Options[i].Text;
arrValues [i]=oField.Options[i].DataValue;
}
for(i=0;i<=items;i++)
{
oField.DeleteOption(i);
}
for(j=items;j>0;j--)
{
var oOption1 =oField.Options;
oOption1.Text=arrTexts[j-1];
oOption1.DataValue= arrValues [j-1];
oField.AddOption(oOption1.Text,oOption1.DataValue);
alert(oOption1.DataValue);
}

Sounds like you need to add a .ForceSubmit in the onSave of the form. This forces CRM to save attribute data changes that you have made with JavaScript.
e.g.
crmForm.all.attribName.ForceSubmit = true;
Check the CRM SDK here: http://technet.microsoft.com/en-us/library/cc189831.aspx

Related

dynamics365 CRM populate form field with user login

I am new to dynamics 365 CRM. I created a form that the user will fill, it contains a lookup field that mapped to the User entity. I want to populate this field automatically depending on the user login. I have tried the business role but it didn't work. I have followed these links:
CRM Auto Populate Field From Option Set.
Auto Populate lookupfield
Dynamics CRM auto populate lookup values from custom field
the Code I am using is :
var userSetting = Xrm.Utility.getGlobalContext().userSettings;
var currentUser = new Array();
currentUser[0] = new Object();
currentUser[0].id = userSetting.userId;
currentUser[0].Name = userSetting.userName;
currentUser[0].entityType = "systemuser";
executionContext.getFormContext().getAttribute("student").setValue(currentUser);
First, retrieve logged in user settings with
var userSettings = Xrm.Utility.getGlobalContext().userSettings
Now, you should have access to the ID, Name, and Type(systemuser) of the record you want to set in your lookup field.
var currentUser = new Array();
var currentUserObject = new Object();
currentUserObject.id = userSettings.userId;
currentUserObject.name = userSettings.userName;
currentUserObject.entityType = "systemuser"
currentUser[0] = currentUserObject;
formContext.getAttribute("fieldname").setValue(currentUser);
From getGlobalContext.userSettings

How do I save multiple selections from List to EF Model?

I am trying to learn how to submit multiple selections from a list to the model created between two data models. I have tried the following:
var tag = context.TagInformation.Find(model.Tags[0]);
var newlyCreatedUser = context.Users.Find(user.Id);
newlyCreatedUser.TagInfo = new List<TagInformation>(0) { tag };
context.SaveChanges();
I have also tried the following:
var tags = new List<TagInformation>();
foreach (var tag in model.Tags)
{
var tag= context.TagInformation.Find(model.Tags[0]);
if (tag != null)
{
tags.Add(tag);
}
}
var newlyCreatedUser = context.Users.Find(user.Id);
newlyCreatedUser.TagInfo = tags;
context.SaveChanges();
I have searched on Google and tried to find what value I need to change here in order to save all selected values from model.Tags, but currently only the first selected value is saved. To my understanding, the [0] is causing it to only save the first selected tag. I need to automatically save any combination of selected tags from the List, regardless of how many tags are in the list.
I can see that all of the select tags are loaded during debugging, and the foreach statement gets passed through for each selected id, but still only saves the first tag selected in the list.
What must I change to obtain this result and where can I find documentation to help me understand? Thanks in advance.
var tag= context.TagInformation.Find(model.Tags[0]);
this line of code always select the first tag, you should do something like
var tag= context.TagInformation.Find(tag);

Google SpreadSheet Api, Putting List-Based Feeds Which Starts on Specific Cell

As seen as Google Api, i can easily put my data into a spreadsheet as below :
namespace MySpreadsheetIntegration
{
class Program
{
static void Main(string[] args)
{
SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1");
// TODO: Authorize the service object for a specific user (see other sections)
// Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
SpreadsheetQuery query = new SpreadsheetQuery();
// Make a request to the API and get all spreadsheets.
SpreadsheetFeed feed = service.Query(query);
if (feed.Entries.Count == 0)
{
// TODO: There were no spreadsheets, act accordingly.
}
// TODO: Choose a spreadsheet more intelligently based on your
// app's needs.
SpreadsheetEntry spreadsheet = (SpreadsheetEntry)feed.Entries[0];
Console.WriteLine(spreadsheet.Title.Text);
// Get the first worksheet of the first spreadsheet.
// TODO: Choose a worksheet more intelligently based on your
// app's needs.
WorksheetFeed wsFeed = spreadsheet.Worksheets;
WorksheetEntry worksheet = (WorksheetEntry)wsFeed.Entries[0];
// Define the URL to request the list feed of the worksheet.
AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);
// Fetch the list feed of the worksheet.
ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
ListFeed listFeed = service.Query(listQuery);
// Create a local representation of the new row.
ListEntry row = new ListEntry();
row.Elements.Add(new ListEntry.Custom() { LocalName = "firstname", Value = "Joe" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "lastname", Value = "Smith" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "age", Value = "26" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "height", Value = "176" });
// Send the new row to the API for insertion.
service.Insert(listFeed, row);
}
}
}
If i wrote "firstname" into the A1 and "lastname" into the B1, this is working, but i want to start this function ie. F21.
I mean, my localname firstname is in the cell F21 and i want google api to put my data "JOE" into F22 cell and ...
How can i do that ?
Regards.
CellFeed will do that, but list feed is more like an SQL style database table.
Suggest you use CellFeed or update your data SQL style, in whole rows.
I gave up with list feed when I discovered how little control you have over the position of the data.
Good examples:
CellFeed
https://gdata-java-client.googlecode.com/svn-history/r51/trunk/java/sample/spreadsheet/cell/CellDemo.java
ListFeed
https://gdata-java-client.googlecode.com/svn-history/r51/trunk/java/sample/spreadsheet/list/ListDemo.java

How to get list of data items list from CRM Metadata Source in code behind?

How to get list of data items list from CRM Metadata Source in code behind?
I have a CRm Metadata Source like
<crm:CrmMetadataDataSource ID="dsquestionOptionset" runat="server" EntityName="contact"
AttributeName="securityquestion"/>
in the html.
I would like to get list of data items in the code behind from the datasource.
"securityquestion" is an intger value and this is linked to an option set.
I tried like
var listOfItems=dsquestionOptionset.Items;
But not possible
Any help is appreciated
Vinu
You'll want to query the Metadata. An example (from here: http://msdn.microsoft.com/en-us/library/gg509035.aspx) would be something like:
RetrieveAttributeRequest retrieveAttributeRequest =
new RetrieveAttributeRequest
{
EntityLogicalName = Contact.EntityLogicalName,
LogicalName = "new_picklist",
RetrieveAsIfPublished = true
};
// Execute the request.
RetrieveAttributeResponse retrieveAttributeResponse =
(RetrieveAttributeResponse)_serviceProxy.Execute(
retrieveAttributeRequest);
// Access the retrieved attribute.
PicklistAttributeMetadata retrievedPicklistAttributeMetadata =
(PicklistAttributeMetadata)
retrieveAttributeResponse.AttributeMetadata;
// Get the current options list for the retrieved attribute.
OptionMetadata[] optionList =
retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray();

How to Update one Sharepoint List (calendar) from Another (custom)?

As part of an EvenReceiver the itemAdded on a custom List (source) creates a Calendar entry in another List (target).
I now want to add an itemUpdated event so that when the the source List is updated the change is filtered through to the target List.
I am using c# in Visual Studio to develop the Event Receiver.
Can anyone please advise the best way to do this and how I create the link between the two Lists to ensure I can update from source to target?
Thank you.
You will have to udpate the target list yourself...
var sourceItem = this.properties.ListItem;
//you can use other properties to search for the item in the targetlist aswell
string query = string.Format("<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>{0}</Value></Eq></Where>", sourceItem.Title);
var spQuery = new SPQuery() { Query = query };
var foundItems = targetList.GetItems(spQuery);
if(foundItems.Count == 1)
{
var foundItem = foundItems[0];
//update the properties you want
foundItem["Property1"] = sourceItem["Property1"];
foundItem["Property2"] = sourceItem["Property2"];
foundItem["Property3"] = sourceItem["Property3"];
foundItem.Update();
}
Note that this piece of code is straight out of my head & untested ;-)

Resources