Retrieve List Items based on condition in Where Clause
Hello Experts,
I am trying to retrieve list items from a list (CityList) which contains 2 columns one is city(string) and State(Lookup) based on Lookup value, but i am getting all city names.
here is my query below.
function MainFunction() {
var lookupid = 5;
var myQueryString = "<Where><Eq><FieldRef Name='State' LookupId='true' /><Value Type='Lookup'>"+lookupid+"</Value></Eq></Where>";
var myContext = new SP.ClientContext.get_current(); ;
var myWeb = myContext.get_web();
var myList = myWeb.get_lists().getByTitle("CityList");
var myQuery = new SP.CamlQuery();
myQuery.set_viewXml(myQueryString);
myItems = myList.getItems(myQuery);
myContext.load(myItems, 'Include(Title)');
myContext.executeQueryAsync(Function.createDelegate(this, GetListDataSuccess), Function.createDelegate(
this, GetListDataFail));
function GetListDataFail(sender, args) {
// Show error message
alert('GetListDataFail() failed:' + args.get_message());
function GetListDataSuccess(sender, args) {
var currListItemCount = myItems.get_count();
var currItemEnumerator = myItems.getEnumerator();
var currItemDetails = '';
while (currItemEnumerator.moveNext()) {
var currItem = currItemEnumerator.get_current();
currItemDetails = currItemDetails + ';' + currItem.get_item("Title");
// Show details
alert(currItemDetails);
Please suggest where i am wrong.
Thank you
saroj
You need to enclose the <Where> tag inside <View><Query> . Try like below
var myQueryString = "<View><Query><Where><Eq><FieldRef Name='State' LookupId='TRUE' />
<Value Type='Lookup'>"+lookupid+"</Value></Eq></Where></Query></View>";
Geetanjali Arora | My blogs |
Similar Messages
-
Workflow to grant access to each List item based on a column value
Hi,
I have 2 lists Risks and RisksLookup.
In Risks, I have Title, Description, service impacted and status columns.
In RisksLookup, I have service impacted, AD1, AD2, AD3, AD4 and AD5.
I have a requirement where in I have to write a Workflow to provide access to each List item based on the value of service impacted. i.e. If service impacted in Risks List is Client A, I have to lookup what all AD groups are present for Client A in RisksLookup
List and provide access to only those groups for that item.
Regards, Shreyas R SHi
another approach
create 5 more lists, dedicated to each impacted service. for Each one these lists apply needeed right ( based onAD groups )Keep you main list where first level will add new items . Attach a workflow to this main list, which will start when an item
is added and which will add specific item's value to his new list ( based on impacted service value )
Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you. -
Display list items based on another list item
Hi All
I want to display the list item based on another list item, but its not working.
This is my code:
/*WHEN-NEW-FORM-INSTANCE*/---Its working.
DECLARE
rg_district recordgroup;
rg_name VARCHAR2 (40) := 'district';
vtemp NUMBER;
BEGIN
rg_district := FIND_GROUP (rg_name);
IF ID_NULL (rg_district)
THEN
rg_district :=
CREATE_GROUP_FROM_QUERY (rg_name,
'select dist,dist from district_mas'
vtemp := POPULATE_GROUP (rg_district);
POPULATE_LIST ('BLOCK3.DISTRICT', rg_name);
END IF;
END;
*/WHEN-LIST-CHANGED*/---Not working. Cannot populate the list based on the List
DECLARE
rg_branch recordgroup;
rg_name1 VARCHAR2 (1000) := 'branch';
vtemp NUMBER;
BEGIN
rg_branch := FIND_GROUP (rg_name1);
IF NOT ID_NULL (rg_branch)
THEN
DELETE_GROUP (rg_name1);
rg_branch :=
CREATE_GROUP_FROM_QUERY
('rg_branch',
'SELECT branch FROM dist_branch WHERE district IN (SELECT DIST FROM DISTRICT_MAS WHERE DISTRICT ='
|| :BLOCK3.DISTRICT
vtemp := POPULATE_GROUP (rg_branch);
POPULATE_LIST ('BLOCK3.BRANCH', rg_branch);
END IF;
END;
Table:
CREATE TABLE DISTRICT_MAS
DIST VARCHAR2(100 CHAR)
CREATE TABLE DIST_BRANCH
DISTRICT VARCHAR2(100 CHAR),
BRANCH VARCHAR2(100 CHAR)
Values:
insert into district_mas values('chennai');
insert into district_mas values('coimbatore');
insert into dist_branch values('chennai','chennai_north');
insert into dist_branch values('coimbatore','Podanur');
Regards
Shagar MHmm, not tested.
try this..
--*/WHEN-LIST-CHANGED*/
DECLARE
rg_branch recordgroup;
rg_name1 VARCHAR2 (1000) := 'branch';
vtemp NUMBER;
QT VARCHAR2(10) :='''';
BEGIN
rg_branch := FIND_GROUP (rg_name1);
IF NOT ID_NULL (rg_branch)
THEN
DELETE_GROUP (rg_name1);
rg_branch :=
CREATE_GROUP_FROM_QUERY
('rg_branch',
'SELECT branch FROM dist_branch WHERE district IN (SELECT DIST FROM DISTRICT_MAS WHERE DISTRICT ='
|| QT||:BLOCK3.DISTRICT||QT||')'
vtemp := POPULATE_GROUP (rg_branch);
POPULATE_LIST ('BLOCK3.BRANCH', rg_branch);
END IF;
END;
Hope this works..
Hamid -
Filter list items based on security groups o365
How to filter list items based on security groups in o365.
Hi,
According to your description, my understanding is that you want to filter list items based on the Office 365 security groups.
If that is the case, I suggest you can create a data view to filter the list items with CAML Query like below:
<Where>
<Membership Type="CurrentUserGroups">
<FieldRef Name="VisibleToGroup"/>
</Membership>
</Where>
For more information, please refer the detailed article below:
SharePoint - Filtering a View by Group Membership
Thanks
Best Regards
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected] -
Want 2 populate value in 2nd list item based on value selected in 1st list?
Want 2 populate value in 2nd list item based on value selected in 1st list?
Gaurav -
The 3rd list will not populate because nothing has been selected yet in list 2. The value in list 2 is null, so the loop to populate list (3) has nothing to load. Try the following below. This should seed your 2nd list so the 3rd list will populate.
You will have to declare first_record boolean and first_value to match DESCC.
first_record := true; -- NEW *****
Clear_List('BLOCK2.ITEM2');
FOR CurRec IN (SELECT UNIQUE DESCC DESCC FROM LUTT where LUTT.IDD = :BLOCK2.ITEM1)
LOOP
if first_record = true then -- NEW SECTION *****
first_value := CurRec.DESCC;
first_record := false;
end if;
Add_List_Element('BLOCK2.ITEM2',1,CurRec.DESCC,CurRec.DESCC);
END LOOP;
:block2.item2 := first_value; -- NEW *****
Clear_List('BLOCK2.ITEM3');
FOR CurRec2 IN (SELECT UNIQUE DESCC DESCC FROM LUTT where LUTT.DESCC = :BLOCK2.ITEM2)
LOOP
Add_List_Element('BLOCK2.ITEM3',2,CurRec2.DESCC,CurRec2.DESCC);
END LOOP;
My name is Ken, 1990 is when I started using Oracle Forms 3.0, character based in the Unix environments. And you are very welcome. -
CAML Query to Sort SharePoint list items based on Modified date
hi ,
can we sort sharePoint list items based on 'Modified' column, the sorting should be done up to milliseconds level.
currently i am using CAML query as below
<OrderBy><FieldRef Name='Modified' Type='DateTime' IncludeTimeValue='TRUE' Ascending='False'/></OrderBy>but its not considering milliseconds while sorting.
Thanks and Regards,
venkatesh.Veda, thanks but I'm not really a hardcore C# coder.
We found more elegant solution was to create a List View which returns all records that should be deleted, based on our own custom deletion criteria, and then create an very simple SSIS Package in Visual Studio using the
Sharepoint Connectors for SSIS to delete all Sharepoint List Items returned from that List View. The Sharepoint Destination Connector has a delete operation.
This worked for us and didn't require any coding. -
Populate the values to list item based on a check box
Hi,
How can i populate the values from a field on the form to one list item based on a check box,
the pseudo code is like,
if checkbox = checked then
populate the particular field value to the list item;
checkbox = unchecked;
next_record;
end if;
Thanks
BcjTo populate a Tlist item, do the following:
1. Create a TLIST item in the EMP block. and give it a height to accommodate several names.
2. Using the TLIST property pallete:
a. Set the Column Name property to EMPNO
b. Click on the Elements in List property. Delete each List Element and delete each List Item Value. If you don't do this you will get an error when you compile.
3. Create a record group using this query:
select ename, to_char(empno) from emp
4. Create a WHEN-NEW-FORM-INSTANCE trigger, and place this code inside the trigger:
Declare
err_num number;
Begin
clear_list('YOUR_TLIST');
err_num := populate_group('YOUR_RECORD_GROUP');
If err_num = 0 Then
populate_list('YOUR_TLIST', 'YOUR_RECORD_GROUP');
Else
message('Error populating Tlist');
message('Error populating Tlist');
End If;
End;
5. Compile and run the form. The ENAMEs will appear in the TList, and each ENAME will have a value equal to its EMPNO. -
Problem in case of or condition in where clause in case of leftouter joi.
hi
i am encountering a wierd problem.
in a select query if i have a left outer join and a or condition in where clause the order of condition in or matters and if i use a to_char problem is solved.
see query below
select * from custsupp left outer join Salesperson s on custsupp.sales_rep = s.id ,state a where (CS_FLAG='C' or CS_flag ='B') and custsupp.state = a.id
i have a single record in table custsupp with CS_FLAG ='B' the above does not return result. but if i move CS_FLAG='B' on left of or i.e
select * from custsupp left outer join Salesperson s on custsupp.sales_rep = s.id ,state a where (CS_FLAG='B' or CS_flag ='C') and custsupp.state = a.id
i get the rsult.
also if i remove left outer join and keep order of condition as it is i get result i.e
select * from custsupp ,state a where (CS_FLAG='C' or CS_flag ='B') and custsupp.state = a.id
also if i add a to_char to co,umns CS_FLAG i get the result.
select * from custsupp left outer join Salesperson s on custsupp.sales_rep = s.id ,state a where (to_char(CS_FLAG)='C' or to_char(CS_flag ='B')) and custsupp.state = a.id
why it is so?
CS_flag is of type nchar
Shreyas
Edited by: shreyasd on Jun 9, 2010 11:07 PMFirst if you don't want to take credit of the free sample then follow the below procedure:
1. Do the GRN for all the three item and for the free item in the excise tab at the item level select the material as non cenvatable. Just remember to add base value of the item
2. If you want to capture the Part1 entry then just do the normal transaction and while posting the excise with J1IEX just remove the excise duties for the free item.
3. For paying the vendor the excise amount, just do subsequent debit in the MIRO and in the details tab add in the unplanned delivery cost the amount that you want to pay for the excise duties
Second case if you want to take credit of the duties:
1. Do the Normal GRN process, add the base value and excise values for the free item.
2. Post the Excise duites with J1iEX.
3. The with the account entry you can settle the excise payment
Hope this will help you
Enjoyyyyyyyyyyy
Akshit -
How can I pass multiple condition in where clause with the join table?
Hi:
I need to collect several inputs at run time, and query the record according to the input.
How can I pass multiple conditions in where clause with the join table?
Thanks in advance for any help.
Regards,
TDIf you are using SQL-Plus or Reports you can use lexical parameters like:
SELECT * FROM emp &condition;
When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
SELECT &columns FROM &tables &condition;
But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
Best of luck! -
Problem in adding one condition in where clause
Hi,
I am populating this internal table t_bkpf for all entries in gt_covp_ext
select bukrs belnr gjahr
bldat budat cpudt
xblnr waers awtyp awkey
from bkpf
into corresponding fields of table t_bkpf
for all entries in gt_covp_ext
where bukrs eq gt_covp_ext-bukrs and
awtyp eq 'MKPF'.
Here i have to add one more condition in where clause
AWKEY = ( Concatenated string of gt_covp_ext-REFBN + gt_covp_ext-REFGJ )
As i am not using loop at gt_covp_ext.How to implement this condition in Where clause.
Please help.If you did not understood the requirement reply this post.
Mukesh Kumar
Message was edited by:
mukesh kumarHi,
Create a new internal table gt_covp_ext_new with the same structure as gt_covp_ext. Include an extra field in gt_covp_ext_new-concat, to store the concatenated value.
Copy all entries from gt_covp_ext to gt_covp_ext_new.
Loop at gt_covp_ext.
move-corresponding gt_covp_ext to gt_covp_ext_new.
gt_covp_ext_new-concat = gt_covp_ext-REFBN + gt_covp_ext-REFGJ .
append gt_covp_ext_new.
endloop.
Now use this new internal table in the query.
select bukrs belnr gjahr
bldat budat cpudt
xblnr waers awtyp awkey
from bkpf
into corresponding fields of table t_bkpf
for all entries in gt_covp_ext_new
where bukrs eq gt_covp_ext_new-bukrs and
awkey eq gt_covp_ext_new-concat and
awtyp eq 'MKPF'.
Hope this answers your qn.
Regards,
Divya -
Enable or disable particular record in list item based on a corresponding c
Hi,
How can i Enable or disable property of particular record in list item (multi record) based on a corresponding check box(multi record) ,
e.g Form Structure:
if press a button then record should populate where multi_post_query
if my_check_box = 1 then
my_list_item disable to update;
else
my_list_item enable to update;
end if;
now wanted result is like below
my_check_box ---- my_list_item
+----------------------enable
+----------------------enable
+----------------------enable
_----------------------Disable
_----------------------Disable
Here "+" means checked,"_" means unchecked and "enable" means updatable "Disable" means not updatable
the pseudo code is like,
if my_check_box = 1 then
my_list_item enable to update;
else
my_list_item disable to update;
end if;
Note: my_check_box is not updatable
please tell me which trigger and where I should create
Thanks
Edited by: 838602 on Feb 21, 2011 11:12 PM
Edited by: 838602 on Feb 22, 2011 1:40 AMHi Abdetu,
I created WHEN-NEW-RECORD-INSTANCE Trigger at data block level
And I need should work like below pseudo code (sorry for previous pseudo code)
if my_check_box = 1 then
my_list_item disable to update;
else
my_list_item enable to update;
end if;
so change code as
IF :MULTI.PROTECTED_FIELD = 1 THEN
SET_ITEM_PROPERTY ('MULTI.ACTION',REQUIRED , PROPERTY_FALSE );
SET_ITEM_PROPERTY('MULTI.ACTION',NAVIGABLE,PROPERTY_FALSE);
SET_ITEM_PROPERTY ('MULTI.ACTION' ,UPDATE_ALLOWED,PROPERTY_FALSE);
SET_ITEM_PROPERTY ('MULTI.ACTION' ,INSERT_ALLOWED,PROPERTY_FALSE);
:multi.action := 0;
ELSE
SET_ITEM_PROPERTY ('MULTI.ACTION',REQUIRED , PROPERTY_TRUE);
SET_ITEM_PROPERTY('MULTI.ACTION',NAVIGABLE,PROPERTY_TRUE);
SET_ITEM_PROPERTY ('MULTI.ACTION' ,UPDATE_ALLOWED,PROPERTY_TRUE);
SET_ITEM_PROPERTY ('MULTI.ACTION' ,INSERT_ALLOWED,PROPERTY_TRUE);
END IF;
Sorry, still I am not getting desired o/p. even i check item (ACTION) level Trigger
Note: my_check_box is not updatable
that would assign at time of button press (post query) as i mentioned
Edited by: 838602 on Feb 22, 2011 1:41 AM -
Retrieving list items from a specific view using CSOM
How can I query a specific view of a SharePoint List using the C# CSOM? I am dealing with SharePoint Online, so the only option is to use SharePoint.Client.
I have done this using Javascript, and I know how to do this with SharePoint On-Premises, but I haven't found a way to do with for SharePoint online using C#.hi Dkhouri,
thanks for posting your issue, you can create a specific view of a list using CSOM and C#.
Kindly find the code snippet below fort he same.
Code for CSOM :-
// Starting with ClientContext, the constructor requires a URL to the
// server running SharePoint.
ClientContext context = new ClientContext("http:SiteUrl");
// Assume the web has a list named "Announcements".
List announcementsList = context.Web.Lists.GetByTitle("Announcements");
// This creates a CamlQuery that has a RowLimit of 100, and also specifies Scope="RecursiveAll"
// so that it grabs all list items, regardless of the folder they are in.
CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
ListItemCollection items = announcementsList.GetItems(query);
// Retrieve all items in the ListItemCollection from List.GetItems(Query).
context.Load(items);
context.ExecuteQuery();
foreach (ListItem listItem in items)
// We have all the list item data. For example, Title.
label1.Text = label1.Text + ", " + listItem["Title"];
For C#
public CamlQuery CreateInventoryQuery(string searchSku)
var qry = new CamlQuery();
qry.ViewXml =
@"<View>
<Query>
<Where>
<BeginsWith>
<FieldRef Name='SKU' />
<Value Type='Text'>" + searchSku + @"</Value>
</BeginsWith>
</Where>
</Query>
</View>";
return qry;
Also, checkout below mentioned URLs for more details
http://www.c-sharpcorner.com/UploadFile/sagarp/sharepoint-2013-caml-query-for-item-id-with-jquery/
http://msdn.microsoft.com/en-us/library/ff798388.aspx
I hope this is helpful to you, mark it as Helpful.
If this works, Please mark it as Answered.
Regards,
Dharmendra Singh (MCPD-EA | MCTS)
Blog : http://sharepoint-community.net/profile/DharmendraSingh -
hi,
I have created a custom list in my sharepoint :
List1 name: employeedepartment -
Title empdepartment
A D1
B D2
C D3
List2 name: employeedetails
emptitle empname empdepartment(lookup) --> from the list "employeedepartment"
x Ram D1
y Robert D2
z Rahim D3
My task is to create a custom webpart that will be for searching this employee details by entering emptitle
For this, i have created a visual webpart using visual studio 2010, my webpart will be like this:
emptitle ---> TextBox1 Button1--> Text property : Search
empname---> TextBox2
empdepartment--> DropDownList1
For this, i wrote the code as follows:
protected void Button1_Click(object sender, EventArgs e)
using (SPSite mysite = new SPSite(SPContext.Current.Site.Url))
using (SPWeb myweb = mysite.OpenWeb())
SPList mylist = myweb.Lists["employeedetails"];
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>" + TextBox1.Text.ToString() + "</Value></Eq></Where>";
SPListItemCollection myitems = mylist.GetItems(query);
if (myitems.Count > 0)
foreach (SPListItem item in myitems)
string a1 = Convert.ToString(item["empname"]);
string a2 = Convert.ToString(item["empdepartment"]);
TextBox2.Text = a1; // displaying properly
//DropDownList3.SelectedIndex = 1;
It is showing the list item in textbox according to the item entered in the textbox1... But I am stuck to show in the dropdown list.
Suppose, if i enter X in textbox and click on search, then dropdownlist need to show D1,
for Y --> D2 and for Z-> D3... like that.
What code do i need to write in the button_click to show this...
Please don't give any links...i just want code in continuation to my code.Hi,
Since you have got the data you want with the help of SharePoint Object Model, then you can focus on how to populate values and set an option selected in the Drop Down List.
With the retrieved data, you can populate them into the Drop Down List firstly, then set a specific option selected.
Here is a link will show how to populate DropDownList control:
http://www.dotnetfunda.com/articles/show/30/several-ways-to-populate-dropdownlist-controls
Another link about select an item in DropDownList:
http://techbrij.com/select-item-aspdotnet-dropdownlist-programmatically
Best regards
Patrick Liang
TechNet Community Support -
Dynamically changing the list item based on another list item
Hi all,
I have two fields that are list items.
First list item contain two list values: Regular and One-time
In second list item if user select the Regular then below values should appear:
Daily wages
Activity Linked
Fixed Contracts.
Contract Staff
Outsourced
if user select the one-time then below values should appear:
Projects
Repairs & Maint.
Please do the needful.First list item contain two list values: Regular and One-timeYou simply need to add a conditional check to the When-List-Changed (WLC) trigger to see which value was selected. Then, as Manu suggests, you will populate the Poplist based on the selected value.
For an example of how to dynamically populate a Poplist item, take a look at: Forms: How to Dynamically Populate a Poplist.
Hope this helps,
Craig B-)
If someone's response is helpful or correct, please mark it accordingly. -
Listing Items based on criteria e.g. High Priority Items First.
Hi,
One of our customers have a need to List High Priority Items first on the WebTools site.
Let's take two ItemCodes for example: Printer001, and, Monitor001.
>> If these two items are included in the same category then Monitor001 will appear before Printer001 as WebTools sorts in alphabetic ascending order;
>> But, our customer wants Printer001 to appear before Monitor001 as it is an Item higher in priority that Printer001.
I can think of two possible solutions:
1/2) Prefix Items with a number or letter to have it appear first in the WebTools default sort order. E.g. Rename "Monitor001" as "AMonitor001". This will not be possible for existing Items in SAP, so it doen't solve the issue,
Or,
2/2) Customize the Default WebTools Item List block to sort Items based on a User Define field called "pririty". Which might require a lot of effort.
Please advise if anyone else has solved similar issue and how.
Thanks very much for your replies in advance.Hey Kafil ... I think you may be stuck modifying the parts list page or creating something from scratch. I'm not aware of an easy way to do this out of the box.
Maybe you are looking for
-
Is it possible to create a form text field that needs to be filled out in Korean
I have created a flyer for a client in InDesign. It's in Korean. The font I use is Apple SD Gothic. But when I create pdf with form fields from it I can't select that font for the field attribute. Is there a way to embed the font in the pdf for the f
-
How to count the no of digits entered in the NumericField & print the same
Hi! How to count the no of digits entered in the Numberic Field and print the content of Numberic Field. Thanks.
-
dear creative experts i have a 5.1 sb live series without live drive! in kx drivers there is an option that uses the subwoofer jack out as headphone jack out, i really need help cuz' i want 2 have this option in creative drivers 2,it would be very us
-
Last week, I started having a problem opening requested popups. (As in, clicking a button to leave a comment on a blog or clicking pinterest "pin it" buttons, when after you click them, a popup window should open.) I downloaded the newest version of
-
Firefox keeps opening at the last visited site; even though the option for the home page are set to open at google/firefox. I have changed the option also to blank page but still the same results.