我有以下CAMLQuery。
<Query>
<Where>
<Or>
<Or>
<Or>
<Or>
<Or>
<Eq>
<FieldRef Name='Title' />
<Value Type='Text'>Titulo</Value>
</Eq>
<Geq>
<FieldRef Name='Vencimento_x0020_Certid_x00e3_o_' />
<Value Type='DateTime'>txtDataDeCNDTribMobil</Value>
</Geq>
<Leq>
<FieldRef Name='Vencimento_x0020_Certid_x00e3_o_' />
<Value Type='DateTime'>txtDataAteCNDTribMobil</Value>
</Leq>
</Or>
<Geq>
<FieldRef Name='Vencimento_x0020_CND_x002f_INSS' />
<Value Type='DateTime'>txtDataDeCNDINSS</Value>
</Geq>
<Leq>
<FieldRef Name='Vencimento_x0020_CND_x002f_INSS' />
<Value Type='DateTime'>txtDataAteCNDINSS</Value>
</Leq>
</Or>
<Geq>
<FieldRef Name='Vencimento_x0020_CRF' />
<Value Type='DateTime'>txtDataDeCRF</Value>
</Geq>
<Leq>
<FieldRef Name='Vencimento_x0020_CRF' />
<Value Type='DateTime'>txtDataAteCRF</Value>
</Leq>
</Or>
<Geq>
<FieldRef Name='Vencimento_x0020_CND_x0020_Tribu' />
<Value Type='DateTime'>txtDataDeCNDTribFederais</Value>
</Geq>
<Leq>
<FieldRef Name='Vencimento_x0020_CND_x0020_Tribu' />
<Value Type='DateTime'>txtDataAteCNDTribFederais</Value>
</Leq>
</Or>
<Geq>
<FieldRef Name='Vencimento_x0020_Seguro_x0020_de' />
<Value Type='DateTime'>txtDataDeSegurodeVida</Value>
</Geq>
<Leq>
<FieldRef Name='Vencimento_x0020_Seguro_x0020_de' />
<Value Type='DateTime'>txtDataAteSegurodeVida</Value>
</Leq>
</Or>
</Where>
<OrderBy>
<FieldRef Name='Title' />
</OrderBy>
</Query>
代码基本上是:查看包含多列日期的Sharepoint 2013列表,并形成多个日期类型的字段。问题是在我创建的表单之间。CAMLQuery不返回任何东西。CAMLQuery只有一个错误
有人知道如何使用多个日期字段制作CAMLQuery吗?
谢谢
如果您确实想将Title=Titulo计算为
CAML:
<Query>
<Where>
<Or>
<Or>
<Eq>
<FieldRef Name='Title' />
<Value Type='Text'>Titulo</Value>
</Eq>
<Or>
<Or>
<Geq>
<FieldRef Name='Vencimento_x0020_Certid_x00e3_o_' />
<Value Type='DateTime'>txtDataDeCNDTribMobil</Value>
</Geq>
<Leq>
<FieldRef Name='Vencimento_x0020_Certid_x00e3_o_' />
<Value Type='DateTime'>txtDataAteCNDTribMobil</Value>
</Leq>
</Or>
<Or>
<Geq>
<FieldRef Name='Vencimento_x0020_CND_x002f_INSS' />
<Value Type='DateTime'>txtDataDeCNDINSS</Value>
</Geq>
<Leq>
<FieldRef Name='Vencimento_x0020_CND_x002f_INSS' />
<Value Type='DateTime'>txtDataAteCNDINSS</Value>
</Leq>
</Or>
</Or>
</Or>
<Or>
<Or>
<Or>
<Geq>
<FieldRef Name='Vencimento_x0020_CND_x002f_INSS' />
<Value Type='DateTime'>txtDataDeCNDINSS</Value>
</Geq>
<Leq>
<FieldRef Name='Vencimento_x0020_CND_x002f_INSS' />
<Value Type='DateTime'>txtDataAteCNDINSS</Value>
</Leq>
</Or>
<Or>
<Geq>
<FieldRef Name='Vencimento_x0020_CRF' />
<Value Type='DateTime'>txtDataDeCRF</Value>
</Geq>
<Leq>
<FieldRef Name='Vencimento_x0020_CRF' />
<Value Type='DateTime'>txtDataAteCRF</Value>
</Leq>
</Or>
</Or>
<Or>
<Or>
<Geq>
<FieldRef Name='Vencimento_x0020_CND_x0020_Tribu' />
<Value Type='DateTime'>txtDataDeCNDTribFederais</Value>
</Geq>
<Leq>
<FieldRef Name='Vencimento_x0020_CND_x0020_Tribu' />
<Value Type='DateTime'>txtDataAteCNDTribFederais</Value>
</Leq>
</Or>
<Or>
<Geq>
<FieldRef Name='Vencimento_x0020_Seguro_x0020_de' />
<Value Type='DateTime'>txtDataDeSegurodeVida</Value>
</Geq>
<Leq>
<FieldRef Name='Vencimento_x0020_Seguro_x0020_de' />
<Value Type='DateTime'>txtDataAteSegurodeVida</Value>
</Leq>
</Or>
</Or>
</Or>
</Or>
</Where>
<OrderBy>
<FieldRef Name='Title' />
</OrderBy>
</Query>
这是我为我的问题找到的解决方案。我知道这不是世界上最好的代码,但它可以工作:)
calmQuery = "<Query>"+
"<Where>";
//If the Subcontratados is not empty and all the dates are, applies the ""
if(Subcontratados != '' && (txtDataDeCNDTribMobil == '' && txtDataAteCNDTribMobil == '' && txtDataDeCNDINSS == '' && txtDataAteCNDINSS == '' && txtDataDeCRF == '' && txtDataAteCRF == '' && txtDataDeCNDTribFederais == '' && txtDataAteCNDTribFederais == '' && txtDataDeSegurodeVida == '' && txtDataAteSegurodeVida == '')){
calmQuery += "";
//If the Subcontratados is not empty and no other date also applies the AND
}else if(Subcontratados != '' && (txtDataDeCNDTribMobil != '' || txtDataAteCNDTribMobil != '' || txtDataDeCNDINSS != '' || txtDataAteCNDINSS != '' || txtDataDeCRF != '' || txtDataAteCRF != '' || txtDataDeCNDTribFederais != '' || txtDataAteCNDTribFederais != '' || txtDataDeSegurodeVida != '' || txtDataAteSegurodeVida != '')){
calmQuery += "<And>";
//If none of the above conditions applies the OR
}else{
calmQuery += "<Or>";
}
calmQuery += "<Eq>"+
"<FieldRef Name='Title' />"+
"<Value Type='Text'>"+Subcontratados+"</Value>"+
"</Eq>";
if(txtDataDeCNDTribMobil != '' && txtDataAteCNDTribMobil != '' && (txtDataDeCNDINSS != '' || txtDataAteCNDINSS != '' || txtDataDeCRF != '' || txtDataAteCRF != '' || txtDataDeCNDTribFederais != '' || txtDataAteCNDTribFederais != '' || txtDataDeSegurodeVida != '' || txtDataAteSegurodeVida != '')){
calmQuery += "<Or>";
}else if(txtDataDeCNDINSS != '' && txtDataAteCNDINSS != '' && (txtDataDeCNDTribMobil != '' || txtDataAteCNDTribMobil != '' || txtDataDeCRF != '' || txtDataAteCRF != '' || txtDataDeCNDTribFederais != '' || txtDataAteCNDTribFederais != '' || txtDataDeSegurodeVida != '' || txtDataAteSegurodeVida != '')){
calmQuery += "<Or>";
}else if(txtDataDeCRF != '' && txtDataAteCRF != '' && (txtDataDeCNDINSS != '' || txtDataAteCNDINSS != '' || txtDataDeCNDTribMobil != '' || txtDataAteCNDTribMobil != '' || txtDataDeCNDTribFederais != '' || txtDataAteCNDTribFederais != '' || txtDataDeSegurodeVida != '' || txtDataAteSegurodeVida != '')){
calmQuery += "<Or>";
}else if(txtDataDeCNDTribFederais != '' && txtDataAteCNDTribFederais != '' && (txtDataDeCNDINSS != '' || txtDataAteCNDINSS != '' || txtDataDeCRF != '' || txtDataAteCRF != '' || txtDataDeCNDTribMobil != '' || txtDataAteCNDTribMobil != '' || txtDataDeSegurodeVida != '' || txtDataAteSegurodeVida != '')){
calmQuery += "<Or>";
}else if(txtDataDeSegurodeVida != '' && txtDataAteSegurodeVida != '' && (txtDataDeCNDINSS != '' || txtDataAteCNDINSS != '' || txtDataDeCRF != '' || txtDataAteCRF != '' || txtDataDeCNDTribFederais != '' || txtDataAteCNDTribFederais != '' || txtDataDeCNDTribMobil != '' || txtDataAteCNDTribMobil != '')){
calmQuery += "<Or>";
}
//If txtDataDeCNDTribMobil and is txtDataAteCNDTribMobil is not empty
if(txtDataDeCNDTribMobil != '' && txtDataAteCNDTribMobil != ''){
calmQuery += "<And>"+
"<Geq>"+
"<FieldRef Name='Vencimento_x0020_Certid_x00e3_o_' />"+
"<Value Type='DateTime'>"+txtDataDeCNDTribMobil+"</Value>"+
"</Geq>"+
"<Leq>"+
"<FieldRef Name='Vencimento_x0020_Certid_x00e3_o_' />"+
"<Value Type='DateTime'>"+txtDataAteCNDTribMobil+"</Value>"+
"</Leq>"+
"</And>";
}
//If txtDataDeCNDINSS and txtDataAteCNDINSS is not empty
if(txtDataDeCNDINSS != '' && txtDataAteCNDINSS != ''){
calmQuery += "<And>"+
"<Geq>"+
"<FieldRef Name='Vencimento_x0020_CND_x002f_INSS' />"+
"<Value Type='DateTime'>"+txtDataDeCNDINSS+"</Value>"+
"</Geq>"+
"<Leq>"+
"<FieldRef Name='Vencimento_x0020_CND_x002f_INSS' />"+
"<Value Type='DateTime'>"+txtDataAteCNDINSS+"</Value>"+
"</Leq>"+
"</And>";
}
//If txtDataDeCRF and txtDataAteCRF is not empty
if(txtDataDeCRF != '' && txtDataAteCRF != ''){
calmQuery += "<And>"+
"<Geq>"+
"<FieldRef Name='Vencimento_x0020_CRF' />"+
"<Value Type='DateTime'>"+txtDataDeCRF+"</Value>"+
"</Geq>"+
"<Leq>"+
"<FieldRef Name='Vencimento_x0020_CRF' />"+
"<Value Type='DateTime'>"+txtDataAteCRF+"</Value>"+
"</Leq>"+
"</And>";
}
//If txtDataDeCNDTribFederais and txtDataAteCNDTribFederais is not empty
if(txtDataDeCNDTribFederais != '' && txtDataAteCNDTribFederais != ''){
calmQuery += "<And>"+
"<Geq>"+
"<FieldRef Name='Vencimento_x0020_CND_x0020_Tribu' />"+
"<Value Type='DateTime'>"+txtDataDeCNDTribFederais+"</Value>"+
"</Geq>"+
"<Leq>"+
"<FieldRef Name='Vencimento_x0020_CND_x0020_Tribu' />"+
"<Value Type='DateTime'>"+txtDataAteCNDTribFederais+"</Value>"+
"</Leq>"+
"</And>";
}
//If txtDataDeSegurodeVida and txtDataAteSegurodeVida is not empty
if(txtDataDeSegurodeVida != '' && txtDataAteSegurodeVida != ''){
calmQuery += "<And>"+
"<Geq>"+
"<FieldRef Name='Vencimento_x0020_Seguro_x0020_de' />"+
"<Value Type='DateTime'>"+txtDataDeSegurodeVida+"</Value>"+
"</Geq>"+
"<Leq>"+
"<FieldRef Name='Vencimento_x0020_Seguro_x0020_de' />"+
"<Value Type='DateTime'>"+txtDataAteSegurodeVida+"</Value>"+
"</Leq>"+
"</And>";
}
if(txtDataDeCNDTribMobil != '' && txtDataAteCNDTribMobil != '' && (txtDataDeCNDINSS != '' || txtDataAteCNDINSS != '' || txtDataDeCRF != '' || txtDataAteCRF != '' || txtDataDeCNDTribFederais != '' || txtDataAteCNDTribFederais != '' || txtDataDeSegurodeVida != '' || txtDataAteSegurodeVida != '')){
calmQuery += "</Or>";
}else if(txtDataDeCNDINSS != '' && txtDataAteCNDINSS != '' && (txtDataDeCNDTribMobil != '' || txtDataAteCNDTribMobil != '' || txtDataDeCRF != '' || txtDataAteCRF != '' || txtDataDeCNDTribFederais != '' || txtDataAteCNDTribFederais != '' || txtDataDeSegurodeVida != '' || txtDataAteSegurodeVida != '')){
calmQuery += "</Or>";
}else if(txtDataDeCRF != '' && txtDataAteCRF != '' && (txtDataDeCNDINSS != '' || txtDataAteCNDINSS != '' || txtDataDeCNDTribMobil != '' || txtDataAteCNDTribMobil != '' || txtDataDeCNDTribFederais != '' || txtDataAteCNDTribFederais != '' || txtDataDeSegurodeVida != '' || txtDataAteSegurodeVida != '')){
calmQuery += "</Or>";
}else if(txtDataDeCNDTribFederais != '' && txtDataAteCNDTribFederais != '' && (txtDataDeCNDINSS != '' || txtDataAteCNDINSS != '' || txtDataDeCRF != '' || txtDataAteCRF != '' || txtDataDeCNDTribMobil != '' || txtDataAteCNDTribMobil != '' || txtDataDeSegurodeVida != '' || txtDataAteSegurodeVida != '')){
calmQuery += "</Or>";
}else if(txtDataDeSegurodeVida != '' && txtDataAteSegurodeVida != '' && (txtDataDeCNDINSS != '' || txtDataAteCNDINSS != '' || txtDataDeCRF != '' || txtDataAteCRF != '' || txtDataDeCNDTribFederais != '' || txtDataAteCNDTribFederais != '' || txtDataDeCNDTribMobil != '' || txtDataAteCNDTribMobil != '')){
calmQuery += "</Or>";
}
//CLOSE - If the Subcontratados is not empty and all the dates are, applies the ""
if(Subcontratados != '' && (txtDataDeCNDTribMobil == '' && txtDataAteCNDTribMobil == '' && txtDataDeCNDINSS == '' && txtDataAteCNDINSS == '' && txtDataDeCRF == '' && txtDataAteCRF == '' && txtDataDeCNDTribFederais == '' && txtDataAteCNDTribFederais == '' && txtDataDeSegurodeVida == '' && txtDataAteSegurodeVida == '')){
calmQuery += "";
//CLOSE - If the Subcontratados is not empty and no other date also applies the AND
}else if(Subcontratados != '' && (txtDataDeCNDTribMobil != '' || txtDataAteCNDTribMobil != '' || txtDataDeCNDINSS != '' || txtDataAteCNDINSS != '' || txtDataDeCRF != '' || txtDataAteCRF != '' || txtDataDeCNDTribFederais != '' || txtDataAteCNDTribFederais != '' || txtDataDeSegurodeVida != '' || txtDataAteSegurodeVida != '')){
calmQuery += "</And>";
//CLOSE - If none of the above conditions applies the OR
}else{
calmQuery += "</Or>";
}
calmQuery += "</Where>"+
"<OrderBy>"+
"<FieldRef Name='Title' />"+
"</OrderBy>"+
"</Query>";