Blockly how to prevent concatenated blocks from splitting - blockly

In my toolbox.xml I have created a custom block by concatenating multiple blocks, something like
<block type="my_custom_type">
<value name="LIST_REQUIRED">
<block type="lists_create_with" inline="true">
<mutation items="3"></mutation>
<value name="ADD0">
<block type="get_variable"/>
</value>
<value name="ADD1">
<block type="get_variable"/>
</value>
<value name="ADD2">
<block type="get_variable"/>
</value>
</block>
</value>
</block>
in this specific case, a list block is united with my_custom_type block.
After an user drags this new block to the workspace, how do I prevent him from removing the "list" block from the original "my_custom_type" block? At the moment he can do that by clicking on the "list" block, which allows him to take that piece separately.

You can set by attributes in block xml for child blocks , you may try like this
<block type="my_custom_type">
<value name="LIST_REQUIRED">
<block type="lists_create_with" inline="true" deletable="false" movable="false">
<mutation items="3"></mutation>
<value name="ADD0">
<block type="get_variable"/>
</value>
<value name="ADD1">
<block type="get_variable"/>
</value>
<value name="ADD2">
<block type="get_variable"/>
</value>
</block>
</value>
</block>

Related

Loop Through Portion of XML String

I have data from a series of sensors that is delivered via an XML bytes formatted string. To format the XML string from the request, I am leveraging Python's BeautifulSoup with the lxml parser. The code to request this data is as follows:
import sys, os
import urllib.request as req
from bs4 import BeautifulSoup as bs
response = req.urlopen(""+apiaddr+"?username="+apiuser+"&password="+apipass+"&region=760")
ingest = response.read()
soup = bs(ingest, 'xml')
The raw bytes string of the request is as follows, please note that I've shortened the total data requested for brevity:
b'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><observation version="1.1.1"><instance><target><idType>stationId</idType><id>12418</id><name>Wx Sensor 1</name></target><resultOf codeSpace="ICE_SD" timestamp="2022-01-13 14:40:00"><value code="TS" no="1">0.0</value><value code="ST" no="1">4.0</value><value code="AL" no="1">2.0</value><value code="T" no="1">0.7</value><value code="TD" no="1">-6.1</value><value code="WL" no="1">0.01</value><value code="RH" no="1">60</value><value code="TD" no="2">-5.9</value><value code="IL" no="1">0.0</value><value code="SL" no="1">0.0</value><value code="FR" no="1">82.0</value><value code="T" no="2">0.7</value><value code="RH" no="2">60</value></resultOf></instance><instance><target><idType>stationId</idType><id>3171</id><name>Wx Sensor 2</name></target><resultOf codeSpace="ICE_SD" timestamp="2022-01-13 14:40:00"><value code="TS" no="1">-6.0</value><value code="ST" no="1">5.0</value><value code="AL" no="1">2.0</value><value code="TB" no="1">-4.5</value><value code="T" no="1">-6.2</value><value code="TD" no="1">-9.1</value><value code="WD" no="1">130</value><value code="WL" no="1">0.0</value><value code="RH" no="1">80</value><value code="WS" no="1">3.0</value><value code="WSM" no="1">3.8</value><value code="VI" no="1">2000</value><value code="IL" no="1">0.0</value><value code="SL" no="1">0.0</value><value code="WDM" no="1">143</value><value code="FR" no="1">81.0</value></resultOf></instance></observation>'
Using BeautifulSoup's Prettify function print(soup.prettify()), the more elegant view of this string is:
<?xml version="1.0" encoding="utf-8"?>
<observation version="1.1.1">
<instance>
<target>
<idType>
stationId
</idType>
<id>
12418
</id>
<name>
Wx Sensor 1
</name>
</target>
<resultOf codeSpace="ICE_SD" timestamp="2022-01-13 14:40:00">
<value code="TS" no="1">
0.0
</value>
<value code="ST" no="1">
4.0
</value>
<value code="AL" no="1">
2.0
</value>
<value code="T" no="1">
0.7
</value>
<value code="TD" no="1">
-6.1
</value>
<value code="WL" no="1">
0.01
</value>
<value code="RH" no="1">
60
</value>
<value code="TD" no="2">
-5.9
</value>
<value code="IL" no="1">
0.0
</value>
<value code="SL" no="1">
0.0
</value>
<value code="FR" no="1">
82.0
</value>
<value code="T" no="2">
0.7
</value>
<value code="RH" no="2">
60
</value>
</resultOf>
</instance>
<instance>
<target>
<idType>
stationId
</idType>
<id>
3171
</id>
<name>
Wx Sensor 2
</name>
</target>
<resultOf codeSpace="ICE_SD" timestamp="2022-01-13 14:40:00">
<value code="TS" no="1">
-6.0
</value>
<value code="ST" no="1">
5.0
</value>
<value code="AL" no="1">
2.0
</value>
<value code="TB" no="1">
-4.5
</value>
<value code="T" no="1">
-6.2
</value>
<value code="TD" no="1">
-9.1
</value>
<value code="WD" no="1">
130
</value>
<value code="WL" no="1">
0.0
</value>
<value code="RH" no="1">
80
</value>
<value code="WS" no="1">
3.0
</value>
<value code="WSM" no="1">
3.8
</value>
<value code="VI" no="1">
2000
</value>
<value code="IL" no="1">
0.0
</value>
<value code="SL" no="1">
0.0
</value>
<value code="WDM" no="1">
143
</value>
<value code="FR" no="1">
81.0
</value>
</resultOf>
</instance>
</observation>
My question is how can I loop through the individual text entries contained within underneath each sensor branch (Wx Sensor 1, Wx Sensor 2, etc.) of the XML string? My first successful attempt was to use soup.find_all('value'), however I need to be able to map each of the text values to the sensor and compile them into an ordered dictionary.
Thank you for your help!

CAML query with 4 conditions will raise this error "Cannot complete this action.\n\nPlease try again."

I have the following CAML query:-
<View Scope=\"RecursiveAll\"><Query><Where>
<And>
<Contains><FieldRef Name =\"ProjectStage1\" /><Value Type = \"Choice\">closed</Value></Contains>
<Eq><FieldRef Name =\"ProjectPriority1\" /><Value Type = \"Choice\">(1) High</Value></Eq>
<And>
<Leq><FieldRef Name=\"Modified\" /><Value Type=\"DateTime\" IncludeTimeValue=\"False\"><Today OffsetDays=\"-7\"/></Value></Leq>
<Geq><FieldRef Name=\"Modified\" /><Value Type=\"DateTime\" IncludeTimeValue=\"False\"><Today OffsetDays=\"-14\"/></Value></Geq>
</And></And>
</Where></Query></View>
But i am getting this error :-
Cannot complete this action.\n\nPlease try again.
can anyone advice?
I am not sure but I think you are missing one <And> tag in the query.
Please make sure it fallows the rules defined here MSDN - AND.
I didn't have possibility to double check it but maybe something like this should work:
<View Scope=\"RecursiveAll\">
<Query>
<Where>
<And>
<Contains>
<FieldRef Name =\"ProjectStage1\" />
<Value Type = \"Choice\">closed</Value>
</Contains>
<And>
<Eq>
<FieldRef Name =\"ProjectPriority1\" />
<Value Type = \"Choice\">(1) High</Value>
</Eq>
<And>
<Leq>
<FieldRef Name=\"Modified\" />
<Value Type=\"DateTime\" IncludeTimeValue=\"False\">
<Today OffsetDays=\"-7\"/>
</Value>
</Leq>
<Geq>
<FieldRef Name=\"Modified\" />
<Value Type=\"DateTime\" IncludeTimeValue=\"False\">
<Today OffsetDays=\"-14\"/>
</Value>
</Geq>
</And>
</And>
</And>
</Where>
</Query>
</View>
Basically we should fallow these kind of rules when multiple And conditions:
1. Single Condition
<Where>
<Eq><FieldRef Name=’Name’ /> <Value Type=’Text’>Aasai</Value></Eq>
</Where>
2. Two Condtion
<Where>
<And>
<Eq><FieldRef Name=’Title’ /> <Value Type=’Text’>Mr</Value></Eq>
<Eq><FieldRef Name=’Name’ /> <Value Type=’Text’>Aasai</Value></Eq>
</And>
</Where>
3. Three Condtion
<Where>
<And>
<And>
<Eq><FieldRef Name=’Title’ /> <Value Type=’Text’>Mr</Value></Eq>
<Eq><FieldRef Name=’Name’ /> <Value Type=’Text’>Aasai</Value></Eq>
</And>
<Eq><FieldRef Name=’Address’ /> <Value Type=’Text’>Chennai</Value></Eq>
</And>
</Where>
4. Four Condtion
<Where>
<And>
<And>
<Eq><FieldRef Name=’Title’ /> <Value Type=’Text’>Mr</Value></Eq>
<Eq><FieldRef Name=’Name’ /> <Value Type=’Text’>Aasai</Value></Eq>
</And>
<And>
<Eq><FieldRef Name=’Address’ /> <Value Type=’Text’>Chennai</Value></Eq>
<Eq><FieldRef Name=’Country’ /> <Value Type=’Text’>India</Value></Eq>
</And>
</And>
</Where>

CAML query...what is wrong with it?

I have a CAML query that keeps throwing an error.
A first chance exception of type 'System.Web.Services.Protocols.SoapException' occurred in System.Web.Services.dll
The thread 0x1574 has exited with code 0 (0x0).
Yeah so not very descriptive. I am guessing it is something to do with how I am using the "Or" element.
Here is what my query looks like:
<Where>
<And>
<IsNotNull>
<FieldRef Name='myRefID' />
</IsNotNull>
<And>
<Or>
<In>
<FieldRef Name='myRefID' />
<Values>
<Value Type='Number'>1</Value>
<Value Type='Number'>2</Value>
<Value Type='Number'>3</Value>
<Value Type='Number'>4</Value>
...
<Value Type='Number'>499</Value>
</Values>
</In>
<In>
<FieldRef Name='myRefID' />
<Values>
<Value Type='Number'>500</Value>
<Value Type='Number'>501</Value>
<Value Type='Number'>502</Value>
<Value Type='Number'>503</Value>
...
<Value Type='Number'>999</Value>
</Values>
</In>
<In>
<FieldRef Name='myRefID' />
<Values>
<Value Type='Number'>1000</Value>
<Value Type='Number'>1001</Value>
<Value Type='Number'>1002</Value>
<Value Type='Number'>1003</Value>
...
<Value Type='Number'>1111</Value>
</Values>
</In>
</Or>
</And>
</And>
</Where>
Also to note that I need to search for specific IDs hence that is why I am using so many IN clauses. The ids are in order above just for illustration purposes. In my real case example the numbers are not in order. So I can't use a query that searches between a start and ending number.
You could try this query, you don't need operator "and" and "or", remember operators in CAML works only with 2 elements.
<Where>
<And>
<IsNotNull>
<FieldRef Name='myRefID' />
</IsNotNull>
<In>
<FieldRef Name='myRefID' />
<Values>
<Value Type='Number'>1</Value>
<Value Type='Number'>2</Value>
<Value Type='Number'>3</Value>
<Value Type='Number'>4</Value>
<Value Type='Number'>499</Value>
</Values>
</In>
</And>
</Where>
You have a semantic error. Just remove this wrapper element:
<Where>
<And>
<IsNotNull>
<FieldRef Name='myRefID' />
</IsNotNull>
<And> <<================================ remove it
<Or>
<In>
<FieldRef Name='myRefID' />
<Values>
<Value Type='Number'>1</Value>
<Value Type='Number'>2</Value>
To simplify CAML query creation, use the tools:
Caml Designer - the best, in my opinion
MSDN officially recommended tools

SPSiteDataQuery with <in> operator

First of all... the query works. With SPQuery it does. The query yields exactly one result (as expected!).
However as soon as I use SPSiteDataQuery (and I need to) it yields two results.
I realized if I don't use but instead (works in cases where there is only ONE value (such as in the example below) it works and only returns one result.
I am using the operator as suggested by this Microsoft article on querying taxonomy fields with CAML: http://msdn.microsoft.com/en-us/library/ff625182(v=office.14).aspx
If two records are returned the first contains the note field (as desired) and the second one doesn't. All other columns are identical.
So I went forth and omitted that note field from the viewfields selection - ét voilà: 1 result (unfortunately I really need that note field's content!).
<Where>
<And>
<Eq>
<FieldRef ID='c042a256-787d-4a6f-8a8a-cf6ab767f12d' /> <!-- content type name -->
<Value Type='Text'>Standard Teaser</Value>
</Eq>
<And>
<And>
<Or>
<Gt>
<FieldRef ID='51d39414-03dc-4bd0-b777-d3e20cb350f7' /> <!-- publishing exp -->
<Value Type='DateTime'>
<Today/>
</Value>
</Gt>
<IsNull>
<FieldRef ID='51d39414-03dc-4bd0-b777-d3e20cb350f7' />
</IsNull>
</Or>
<Or>
<Leq>
<FieldRef ID='a990e64f-faa3-49c1-aafa-885fda79de62' /> <!-- publishing start -->
<Value Type='DateTime'>
<Today />
</Value>
</Leq>
<IsNull>
<FieldRef ID='a990e64f-faa3-49c1-aafa-885fda79de62' />
</IsNull>
</Or>
</And>
<In>
<!-- taxonomy field -->
<FieldRef ID='CAFEF21A-D977-44F8-96E4-6F6DA6F90A59' LookupId='TRUE' />
<Values>
<Value Type='Integer'>2</Value>
</Values>
</In>
</And>
</And>
</Where>

SharePoint 2010 Expand recurrences CAML Query exceeding list view threshold

Trying to get event items from a list, I issue a CAML query that only returns a small number of items (about 17). When I set the List View Threshold at 10000 everything works fine, but when I set the LVT at 5000, I get a "Exceeded List View Threshold set by the administrator" error.
My CAML query is pretty simple:
<Where>
<And>
<DateRangesOverlap>
<FieldRef Name="EventDate" />
<FieldRef Name="EndDate" />
<FieldRef Name="RecurrenceID" />
<Value Type="DateTime">
<Now />
</Value>
</DateRangesOverlap>
<And>
<BeginsWith>
<FieldRef Name="Place" />
<Value Type="Text">Boston</Value>
</BeginsWith>
<Or>
<Eq>
<FieldRef Name="Status" />
<Value Type="Text">Status1</Value>
</Eq>
<Eq>
<FieldRef Name="Status" />
<Value Type="Text">Status2</Value>
</Eq>
</Or>
</And>
</And>
Can anyone explain why this may be happening? Is is because when expanding recurrences SP actually runs a separate query that result in the LVT being exceeded? Any suggestions to restructure the query would be great, but I do need to look at all occurrences of recurring events (not just the master items).
In case anyone is interested, I've managed to play around with the Query and find out how to avoid hitting the threshold.
What I did was simply change the order of the query elements so that my indexed fields were listed first and the DateRangesOverlap node was listed last. Here is the result that works:
<Where>
<And>
<BeginsWith>
<FieldRef Name="Place" />
<Value Type="Text">Boston</Value>
</BeginsWith>
<And>
<Or>
<Eq>
<FieldRef Name="Status" />
<Value Type="Text">Status1</Value>
</Eq>
<Eq>
<FieldRef Name="Status" />
<Value Type="Text">Status2</Value>
</Eq>
</Or>
<DateRangesOverlap>
<FieldRef Name="EventDate" />
<FieldRef Name="EndDate" />
<FieldRef Name="RecurrenceID" />
<Value Type="DateTime">
<Now />
</Value>
</DateRangesOverlap>
</And>
</And>
</Where>

Resources