How to create lookup field programmatically using AddFieldAsXml Method in Sharepoint 2013? - sharepoint

I have two lists(Invoice & Client) which i had created dynamically through code and i want to create lookup field programmatically for relationship between this two list.
In Invoice List i have following columns:
1.ID
2.InvoiceNo
3.ClientId - this column i need to create as lookup
4.ClientId:ClientName - this column is used to get ClientName from Client List when i enter ID in ClientId Column
5.etc
In Client List i have following columns:
1.ID
2.ClientName
3.Address
4.etc
So far i'm able to create lookfield that is ClientId in invoice list 3rd column but how can i create programmatically 4th column has additional column.
When we create lookup column using sharepoint administration there is an option called "Add a column to show each of these additional fields" this i want to create programmatically
My Code
List refList= webobj.Lists.GetByTitle(Constants.Client);
clientContext.Load(refList);
clientContext.ExecuteQuery();
Field LookUpField = listObj.Fields.AddFieldAsXml(
"<Field Type='Lookup' DisplayName='ClientId' Required='FALSE' List='" + refList.Id + "'
ShowField='ID' StaticName='ClientId'
Name='ClientId' />", true,AddFieldOptions.DefaultValue);
LookUpField.Update();
clientContext.ExecuteQuery();
Thanks

Related

Automate "Vlookup" using Sharepoint Lists, and Flow

I have two lists in sharepoint. List A (Template) and B(population). List A contains column "Employee Login ID" and List B contains "Employee_PrimaryLoginID".
I want to create a vlookup, So whenever a new record in List A gets created, a column named "Submitted" will be edited in List B.
I want to lookup on "Employee Login ID" and ""Employee_PrimaryLoginID" , as "Employee_PrimaryLoginID" in List B is the full set, and when a new record is created(in list A) I want to be able to view that is have been created.
Hopefully this makes sense. Here is what I have tried using Flow:
According to my understanding:
ListA contains column "Employee Login ID"
ListB contains "Employee_PrimaryLoginID" and "Submitted". And ListB has all employees’ login ID, in other words "Employee_PrimaryLoginID" in ListB is the full set.
When ListA creates a new item, if "Employee Login ID" is equal to "Employee_PrimaryLoginID", then update the corresponding item in ListB and set the "Submitted" value to the value of "Employee Login ID".
If yes, please following steps:
1.Set "Employee Login ID" in ListA is unique value and required column
2.Set "Employee_PrimaryLoginID" in ListB is unique value and required column
3.Create Microsoft Flow
4.Save and Test flow
5.When you creating new item, the ListB will happen as shown below:

RunningCount webi Business Objects Formula

I am trying to produce a running count of salesid's for each distinct customer id.
I have tried this formula:
=RunningCount([Order ID])ForAll([Query 1].[Brand Account ID])
And unfortunately it yields this result:
We can see that where 'Count_of_Salesorder' == 12, it should have reset to 1 because the customer id has changed from B000115545 to B000159009
How can I achieve the running count of 'Order ID' for each distinct customer id? (Customer id is the field containing values that begin with 'B000')
You need to specify that you want the count to reset for each value of Brand Account ID.
=RunningCount([Order ID]; ([Brand Account ID]))
If you navigate to the RunningCount function with the Variable Editor and click on the "More on this function" link you will see its documentation.

How to collect data from a form and inset it in another sharepoint list

Good afternoon,
I am creating an app using sharepoint and powerapps, on powerapps I have a form that feeds from a sharepoint list. Now my problem is the following, when I create a new form I would like to submit from another sharepoint because it is going to be easier for me to create reports.
If I understood you correctly, you have a Form tied to a Sharepoint List and you want to copy its contents to another Sharepoint List with the same column structure. Is that correct?
If that is so, this is how you do it:
1) Add both SharePoint Lists (List1 and List2) as DataSources to your app
2) Set your form's Data source to List1
3) Select the fields you want to edit
4) Add a button to your form. Set the OnSelect value of the button to this:
Patch( 'List2', Defaults( 'List2' ), { Column1: val1, Column2: val2, etc.. } )
where val1, val2 etc.. are values you entered into your controls
Ex: = txtFirstName.Text, ddlStartDate.SelectedDate etc..
NOTE: Your column names have to match the exact spelling of the column names on List 2. If you have any multi word column names, put them in single quotes. Ex: 'First Name'
See: https://learn.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch
and https://learn.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-defaults

Kentico - Form Control Drop-down List & SQL Query

I couldn't make the title clearer, but here's what I need help with.
I have a custom page type [1] for Leaders which includes 2 fields: Name, and Title. This holds the list of all leaders at the company.
I have another custom page type [2] for Speaking Events, which includes a field called Speaker to display the speaker's name and title. This field was set up as a drop-down list with data source from a SQL Query to query the Leaders data in [1].
Select LeadersID, Name, Title from co_leaders order by Name
I got it work fine - the drop-down displays a list of Name. However, what I wanted to display in the drop-down option is: Name, Title (not just Name) like below so that I only pick one and have both Name and Title. Is it possible to do this?
John Doe, CEO
Jane Doe, CFO
Hope it's clear and thanks for your input!
This is the SQL you are looking for:
SELECT LeadersID, Name + ', ' + Title FROM co_leaders ORDER BY Name
You need to do a concatenation of the column values (Name and Title), as opposed to selecting the columns separately.
EDIT: This is assuming that Name and Title are not nullable fields.
If there is a NULL value in any of the concatenated fields, the end value will be NULL. In this case, you will need to use COALESCE (or an equivalent function) to define an alternative value. For example:
SELECT LeadersID, Name + ', ' + COALESCE(Title, 'Member') FROM co_leaders ORDER BY Name

Sharepoint update Lookup Column

I am trying to update a Lookupvalue field "Items" via the SharePoint object model.
"Products" is a column in one list which is used as a lookup column to another list in field "Items".
In my webpart i have dropdown of Items now
string strItems = ddlItems.SelectedValue.ToString();
item["Items"] = new SPFieldLookupValue("strItems");
item.Update();
However, this is causing an error
Internally, SharePoint stores these references like this:
NumericID;#DisplayValue i.e.
145;#Soup
12;#Cake
874;#Steak
That is the kind of thing that should be in the constructor to SPFieldLookupValue. Or if it is more helpful, use the variant of the constructor that takes an int id and string display value.
More info is laid out here:
http://blogs.msdn.com/b/sridhara/archive/2007/08/25/update-quot-lookup-quot-fields-in-sharepoint-2007.aspx
You need to set the Items column to the ID of the SPItem represented by the product. You could do this by setting the DataTextValue of your dropdown to ID and then using the SelectedValue. You could also do a CAML query when a new item is selected in the dropdown.
You can find more information at the bottom of this blog post:
http://weblogs.asp.net/bsimser/archive/2005/05/13/406734.aspx

Resources