getting list of records in a subgrid using webapi or fetchxml - dynamics-crm-2011

I want to get list of all records that are in a subgrid in a form
Is there a way to get it using some api call or using javascript?
The below code will fetch the rows if the subgrid is available in the form but
I don't want to have the subgrid in the form where I am going to fetch these records
var selectedRows = Xrm.Page.getControl("Contacts").getGrid().getSelectedRows();
var rows = Xrm.Page.getControl("Contacts").getGrid().getRows();
For example, assume that I have a medicalCase entity form, where I am having patients subgrid. I want to get the list of records in the patients subgrid using webapi in some other entity form

Yes, you can retrieve records using fetch.
Determine the fetchxml behind your view. Easiest way to do this is to pull up your view in Advanced Find and then use the Download Fetch Xml button.
Use a library like the xrmservicetoolkit to execute your fetch statement.
var fetchXml =
"<fetch mapping='logical'>" +
"<entity name='contact'>" +
"<attribute name='contactid' />" +
"<attribute name='firstname' />" +
"<attribute name='lastname' />" +
"<attribute name='accountrolecode' />" +
"<filter>" +
"<condition attribute='contactid' operator='eq' value='" + contactId + "' />" +
"</filter>" +
"</entity>" +
"</fetch>";
var retrievedContacts = XrmServiceToolkit.Soap.Fetch(fetchXml);
console.log(retrievedContacts[0].attributes['lastname'].value)
See this page for more info.

Related

Sharepoint calculated field formula syntax

I have to programmatically set the formula for a calculated field in a list.
This field has to be the sum of two other fields. Can you provide me with the syntax for the formula that I have to insert in the code? I cannot find any example.
Can you provide me also with a reference for formula syntax because I have also to create another calculated field which is the concatenation of two string fields.
Thank you
Calculated Field Formulas reference:
For your task use simply:
=[Column1] + [Column2]
Create Calculated field with server code reference
using (SPWeb oWebsite = SPContext.Current.Site.AllWebs["Website_Name"])
{
SPList oList = oWebsite.Lists["MyList"];
SPFieldCollection collFields = oList.Fields;
string strNewFieldName = collFields.Add("MyNewColumn",
SPFieldType.Calculated, false);
SPFieldCalculated strNewField =
(SPFieldCalculated)collFields[strNewFieldName];
strNewField.Formula = "=[Column1]<[Column2]";
strNewField.Update();
}
Create Calculated field with CSOM code reference1, reference2. As you see below you need to remeember about escape special characters in xml.
string formula = "<Formula>=FirstName& \" \" &LastName& \" (id: \" &EmployeeID& \" \"</Formula>"
+ "<FieldRefs>"
+ "<FieldRef Name='FirstName' />"
+ "<FieldRef Name='LastName' />"
+ "<FieldRef Name='EmployeeID' />"
+ "</FieldRefs>";
string schemaCalculatedField = "<Field ID='<GUID>' Type='Calculated' Name='FullName' StaticName='FullName'
DisplayName='Full Name' ResultType='Text' Required='TRUE' ReadOnly='TRUE'>" + formula + "</Field>";
Field fullNameField = demoList.Fields.AddFieldAsXml(schemaCalculatedField, true, AddFieldOptions.AddFieldInternalNameHint);
clientContext.ExecuteQuery();
Working code for your implementation (comments):
string formula = "<Formula>=Nome1&" "&Cognome1&"(id:"&Campo1&")"</Formula>" + "<FieldRefs>" + "<FieldRef Name='Nome1'/>" + "<FieldRef Name='Cognome1'/>" + "<FieldRef Name='Campo1'/>" + "</FieldRefs>";
string schemaCalculatedField = "<Field ID='1F2ABCC0-D243-40F0-A18D-E0AEF7FE3EB6' Type='Calculated' Name='FullName' StaticName='FullName' DisplayName='Full Name' ResultType='Text' Required='TRUE' ReadOnly='TRUE'>" + formula + "</Field>";
Field fullNameField = context.Web.Lists.GetByTitle("PnP Custom List3").Fields.AddFieldAsXml(schemaCalculatedField, true, AddFieldOptions.AddFieldInternalNameHint);
context.ExecuteQuery();

How to get the Image URL from Picture Library and folders in SharePoint

I want to get the Image URL from picture library and from the folders inside the library in SharePoint. I have tried both internal names ows_FileRef and ows_EncodedAbsUrl.
For ows_FileRef it is showing id and # in front of the image url.
For ows_EncodedAbsUrl it is showing as undefined.
Please help me to figure it out.
You can use the following code to iterate through folders as per your requirement:
SPFolder folder = ListPicture.RootFolder.SubFolders["picLib"];
And then you can use SpQuery to get the data:
string SPtestQuery = "<Where><Eq><FieldRef Name='ContentTypeId'/><Value Type='ContentTypeId'>"
+ GlobalConfiguration.Current.Items[Constants.ConfigurationKeys.ContentTypeID]
+ "</Value></Eq></Where><OrderBy><FieldRef Name='Date' Ascending='FALSE' /></OrderBy>";
string SPTestFields = string.Concat(
"<FieldRef Name='FileLeafRef'/>",
"<FieldRef Name='FileDirRef'/>",
"<FieldRef Name='ID'/>",
"<FieldRef Name='GalleryImage'/>",
"<FieldRef Name='Title'/>");
string listUrl = SPUrlUtility.CombineUrl(web.Url, "picLib");
You can get the data in datatable.

Create an iconNote Document in a new database

This is a more explicite extension on my previous question.
From an button on an XPage I create a new database
targetDB = dir.createDatabase(fileName);
I then copy a bunch of stuff into the targetDB from the sourceDB. I then want to set the launch properties in the targetDB which is where the problem comes.
I know that I can get the iconNote = targetDB.getDocumentByID("FFFF0010") except there is no iconDoc in the target. Does anyone have a way to create this doc with the specific NoteID?
I tried copying the iconNote document from the sourceDB to the targetDB but that does not work. Changes the UNID and noteID. Can't find any database method to create an icon Note.
Found lots of stuff on how to change the settings in the iconNote, but nothing on how to create one if there is not one in the database.
Thanks to Jesse I took his code and changed it to SSJS and it works fine.
var dir:NotesDbDirectory = session.getDbDirectory("Development");
var newDB:NotesDatabase = dir.createDatabase("XPages/install/created.nsf");
var importer:NotesDxlImporter = session.createDxlImporter();
importer.setDesignImportOption(6);
var dxl:String = "<?xml version='1.0'?>\n" +
"<note default='true' class='icon'>\n" +
" <item name='$TITLE'>\n" +
" <text>Test Title</text>\n" +
" </item>\n" +
" <item name='$Flags'>\n" +
" <text>J7NZq?!</text>\n" +
" </item>\n" +
"</note>\n";
importer.importDxl(dxl, newDB);
var iconNote = newDB.getDocumentByID("FFFF0010");
iconNote.replaceItemValue("$DefaultXPage", "xpWFSDemo.xsp");
iconNote.replaceItemValue("$DefaultClientXPage", "xpWFSDemo.xsp");
iconNote.save();
dBar.info(iconNote.getItemValueString("$Flags"));
Something like this oughta do it:
DbDirectory dir = session.getDbDirectory(null);
Database newDB = dir.createDatabase("tests/created.nsf");
DxlImporter importer = session.createDxlImporter();
importer.setDesignImportOption(DxlImporter.DXLIMPORTOPTION_REPLACE_ELSE_CREATE);
String dxl = "<?xml version='1.0'?>\n" +
"<note default='true' class='icon'>\n" +
" <item name='$TITLE'>\n" +
" <text>Some DB Title</text>\n" +
" </item>\n" +
" <item name='$Flags'>\n" +
" <text>J7NZq?!</text>\n" +
" </item>\n" +
"</note>\n";
importer.importDxl(dxl, newDB);
That's with the two "open XPage" options set already - you could also include the two XPage name items the same way, and it may be a good idea to export the icon note from an existing DB (database.getDocumentByID("FFFF0010").generateXML()) and paste in the actual icon item as well, since this DXL will result in an icon-less database. Nonetheless, it seems to work in my testing as a basis.
And after that point, you'll be able to fetch the icon note using the usual "FFFF0010" pseudo-ID and replace item values the same way I mentioned before.

How to update a sharepoint list item via web services using a where clause?

I would like to update a list item using SharePoint and am stuggling to find 1 decent CAML example.
Here is what I want to do, in SQL my query would look something like this
update [table] set field='value' where fieldID = id;
so this would mean I have 1 item in a list I would like to update 1 field on given the ID of that listitem.
I've tried this, but it doesn't work:
batchElement.InnerXml = "<Method ID='1' Cmd='Update'>" +
"<Field Name='DeliveryStatus'>" + newStatus.ToString() + "</Field>" +
"<Where><Eq><FieldRef Name='ID' /><Value Type='Text'>" + id + "</Value></Eq></Where></Method>";
I'll add this answer for the community, although it might not answer all your questions.
batchElement.InnerXml = "<Method ID='1' Cmd='Update'>" +
"<Field Name='ID'>" + id + "</Field>" +
"<Field Name='DeliveryStatus'>" + newStatus.ToString() + "</Field></Method>";
It seems the first field you specify is the where clause.
I have no idea how you would do any advanced filtering with this (nots or exclusions or in clauses or ranges). But hope this basic info helps.
You don't need use the where clause to update a list item.
atchElement.InnerXml = "<Method ID='1' Cmd='Update'>" +
"<Field Name='DeliveryStatus'>" + newStatus.ToString() + "</Field>" +
"<FieldRef Name='ID' /><Value Type='Text'>" + id + "</Value></Method>";
The only think you need do is to provide the ID like above.

Cross site data wss 3.0 sharepoint

I am trying to create a web part which will list all the items from the site collection i.e. from each web site's document library. I am using the following code.
SPWeb web = SPContext.Current.Web;
SPSiteDataQuery query = new SPSiteDataQuery();
//Ask for all lists created from the document library template.
query.Lists = "<Lists ServerTemplate=\"101\" />";
// Get the Name field.
query.ViewFields = "<FieldRef Name=\"Title\" />";
// Set the sort order.
query.Query = "<OrderBy>" +
"<FieldRef Name=\"Created\" Ascending=\"False\" />" +
"</OrderBy>";
// Query all Web sites in this site collection.
query.Webs = "<Webs Scope=\"SiteCollection\" />";
DataTable dt = web.GetSiteData(query);
DataView dv = new DataView(dt);
My site collection contains nested sub sites and work spaces with different document libraries. The web part is rendered perfectly but it only shows the column Title because it is specified in ViewFields.
Is it possible to show the column Name (linked to document with edit menu), so that each item will be appeared as hyperlink and on click of this link it will open the item in respective application e.g. in Microsoft Word 2007.
Please help me in this regard.
Try using SPGridView. An example is located here.

Resources