Using client object model, with below caml query able to fetch items with in a folder, but seeing a way to get "folder" field values where these items or documents is residing.
+ "<Query>"
+ " <Where>"
+ " <Eq><FieldRef Name='FSObjType' /><Value Type='int'>0</Value></Eq>"
+ " </Where>"
+ "</Query>"
My code for retrieving folder information...
string strFieldValue = string.Empty;
CamlQuery qryFolder = new CamlQuery();
qryFolder.ViewXml = #"<View Scope='RecursiveAll'>"
+ "<Query>"
+ " <Where>"
+ " <And>"
+ " <Eq><FieldRef Name='FSObjType' /><Value Type='int'>1</Value></Eq>"
+ " <Eq><FieldRef Name='FileRef' /><Value Type='Text'>"+folderName+"</Value></Eq>"
+ " </And>"
+ " </Where>"
+ "</Query>"
+ "<ViewFields>"
+ "<FieldRef Name='Title' /><FieldRef Name='FieldValue' /><FieldRef Name='FileRef' />"
+ "</ViewFields>"
+ "</View>";
qryFolder.FolderServerRelativeUrl = rootFolder;//+#"/"+folderName;
ListItemCollection itemColl = docs.GetItems(qryFolder);
context.Load(itemColl);
context.ExecuteQuery();
if (itemColl.Count == 1)
{
strFieldValue = itemColl[0]["FieldValue"].ToString();
}
return strFieldValue
I get a value here when used caml query with FSObjType is 1 which is for only folders... but unfortunately i get null when query with FSObjType is 0 which queries only files. My requirement is to get a value even when you are at the file level... Not sure if i'm going correct with the CAML query..
Thanks,
Jameel
add to you query this "<View Scope=\"RecursiveAll\"> ", just before the + "<Query>"
more details https://sharepoint.stackexchange.com/questions/29405/get-items-under-folder-caml
Related
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();
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.
I try to get some files from a folder, inside a folder inside a list. To do this, I try to use a CalmQuery with a RowLimit because I have lot of files in this folder.
But when I execute the code, it appears that my row limit didn't work.
$list = $context.Web.Lists.GetByTitle($ListName)
$context.Load($list)
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = "<View Scope='RecursiveAll'> " +
"<RowLimit>5000</RowLimit>"+
"<Query>" +
"<OrderBy>"+
"<FieldRef Name='FileLeafRef' Ascending='True' />"+
"</OrderBy>"+
"<Where>" +
"<Eq>"+
"<FieldRef Name='FileLeafRef' />"+
"<Value Type='File'>EDMS API/APICAL Invoice</Value>"+
"</Eq>"+
"</Where>"+
"</Query>"+
"</View>"
$listItems = $list.getItems($query)
$context.Load($listItems)
$context.ExecuteQuery()
Most likely it's not an RowLimit issue but rather the Query expression itself. The query:
<Where>
<Eq>
<FieldRef Name='FileLeafRef' />
<Value Type='File'>{value}</Value>
</Eq>
</Where>
returns items those names match {value}, which in turn does not return the files located under a specific folder which url specified in {value}.
If you want to include only files located in specific folder you could consider at least the following two approaches.
Assume the following structure:
News (sub site)
|
Documents (library)
|
Archive (folder)
Then the following examples demonstrate how to include items from Archive folder:
1 Set folder via CamlQuery.FolderServerRelativeUrl property:
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = "<View Scope='RecursiveAll'> " +
"<RowLimit>20</RowLimit>"+
"<Query>" +
"<OrderBy>"+
"<FieldRef Name='FileLeafRef' Ascending='True' />"+
"</OrderBy>"+
"</Query>"+
"</View>"
$query.FolderServerRelativeUrl = "/News/Documents/Archive"
$listItems = $list.getItems($query)
$context.Load($listItems)
$context.ExecuteQuery()
2 Set folder via FileDirRef property
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = "<View Scope='RecursiveAll'> " +
"<RowLimit>20</RowLimit>"+
"<Query>" +
"<OrderBy>"+
"<FieldRef Name='FileLeafRef' Ascending='True' />"+
"</OrderBy>"+
"<Where>" +
"<Eq>"+
"<FieldRef Name='FileDirRef' />"+
"<Value Type='File'>/News/Documents/Archive</Value>"+
"</Eq>"+
"</Where>"+
"</Query>"+
"</View>"
$listItems = $list.getItems($query)
$context.Load($listItems)
$context.ExecuteQuery()
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.
Pagination (Next button) doesn't work for custom BusinessDataListWebPart.
I am adding BusinessDataListWebPart using code. Everything works fine. I can see 20 data raw at the same time but when I click "Next Button", I can not see next 20-40 data. A postback occurs, but the pageindex never changes.
I am using following code to add BusinessDataListWebPart to the Sharepoint site.
BusinessDataListWebPart consumer = new BusinessDataListWebPart();
consumer.Title = title;
consumer.Application = instance.Name;
consumer.Entity = projEntity.Name;
consumer.XslLink = "/Style%20Library/XSL%20Style%20Sheets/" + xslFileName;
consumer.PageSize = 20;
OK..I found the answer.
For pagination I needed to add "ParameterBindings" to the business data list webpart.
My final code is, It works perfect.
BusinessDataListWebPart consumer = new BusinessDataListWebPart();
ServerContext serverContext = ServerContext.GetContext(site);
SqlSessionProvider.Instance().SetSharedResourceProviderToUse(serverContext);
LobSystemInstance instance = ApplicationRegistry.GetLobSystemInstanceByName(applicationName);
Entity projEntity = instance.GetEntities()[entityName];
consumer.Title = title;
consumer.Application = instance.Name;
consumer.Entity = projEntity.Name;
consumer.XslLink = "/Style%20Library/XSL%20Style%20Sheets/" + xslFileName;
consumer.PageSize = 20;
consumer.ParameterBindings = "<ParameterBinding Name=" + "\"dvt_firstrow\"" + " Location=" + "\"Postback;Connection\"" + "/>" +
" <ParameterBinding Name=" + "\"dvt_sortdir\"" + " Location=" + "\"Postback;Connection\"" + "/>" +
" <ParameterBinding Name=" + "\"dvt_sortfield\"" + " Location=" + "\"Postback;Connection\"" + "/>" +
" <ParameterBinding Name=" + "\"dvt_filterfields\"" + " Location=" + "\"Postback;Connection\"" + "/>" +
" <ParameterBinding Name=" + "\"dvt_partguid\"" + " Location=" + "\"Postback;Connection\"" + "/>";