How to get the name of an OptionSet in Power Apps Portal with Liquid tags? - fetchxml

The result set below is the response from a fetchXML query.
<resultset morerecords="0" >
<result/>
<result>
<trit_courseschedule name="Synchronous" formattedvalue="314310000" >
314310000
</trit_courseschedule>
</result>
<result>
<trit_courseschedule name="Asynchronous" formattedvalue="314310001" >
314310001
</trit_courseschedule>
</result>
</resultset>
How would you get the value of "name" from above result set? I did trit_courseschedule.name, but what it's supposed to be is trit_courseschedule.label, as you are getting the label of that option set. I wanted this to be out there for those who might have stumbled upon this issue like I did.

The Option Set variable in Common Data Service is made of two attributes the value and the label.
The Value is the internal Id each option in the set of options.
The Label is the name assigned to each option in the set of options.
So in order to get to the Label with liquid tags you must use the following:
{{yourEntityVariable.yourOptionSetAttribute.Label}}

Related

Unable to set a null value when manipulating xml

I have the following xml:
<Company>
<Section>ABC</Section>
</Company>
I am conducting a negative test of sorts and want to send a NULL value to the "Section" element of the xml.
I tried the following:
* set xml /Company/Section = (null)
However, what happens is that the opening tag of the element gets deleted altogether resulting in:
<Company>
</Section>
</Company>
Expected result should be:
<Company>
<Section></Section>
</Company>
I would've liked to try .replace but the value inside "Section" is dynamic and so I cannot effectively use .replace. I also tried an empty string ('') and the same behavior happens where the opening tag gets deleted.
Please advise.
That is exactly what a null should do.
If an empty string does not work, that is a big surprise to me. Then the best option is you submit an issue and ideally contribute a PR to fix it also. Else consider what you ask for as not supported.

SQL get value from XML in tag, by tag value

I have the following XML:
<Main>
<ResultOutput>
<Name>TEST1</Name>
<Value>D028</Value>
</ResultOutput>
<ResultOutput>
<Name>TEST2</Name>
<Value>Accept</Value>
</ResultOutput>
<ResultOutput>
<Name>TEST3</Name>
<Value />
</ResultOutput>
</Main>
What I want is to get the value of the <value> tag in SQL.
Basically want to say get <value> where <Name> has the value of TEST1, as an example
This is what I have at the moment, but this depends on the position of the XML tag:
XMLResponse.value(Main/ResultOutput/Value)[5]', nvarchar(max)')
The best way to do this is not to put extra where .value clauses, but to do it directly in XQuery.
Use [nodename] to filter by a child node, you can even nest such predicates. text() gets you the inner text of the node:
XMLResponse.value('(/Main/ResultOutput[Name[text()="TEST1"]]/Value/text())[1]', 'nvarchar(max)')
Below is an example using the sample XML in your question. You'll need to extend this to add namespace declarations and the proper xpath expressions that may be present in your actual XML as your query attempt suggests.
SELECT ResultOutput.value('Value[1]', 'nvarchar(100)')
FROM #xml.nodes('Main/ResultOutput') AS Main(ResultOutput)
WHERE ResultOutput.value('Name[1]', 'nvarchar(100)') = N'TEST1';

Field value query with special character and unfiltered search returning unexpected results?

Field value query is giving unexpected results when any special character(#,=,#,$,%,^,*) is passed.
please find the 4 sample docs I have inserted in to ML.
<root>
<journalTitle>Dinesh</journalTitle>
<sourceType>JA</sourceType>
<title>title1</title>
<volume>volume0</volume>
</root>
<root>
<journalTitle>Gayari</journalTitle>
<sourceType>JA</sourceType>
<title>title1</title>
<volume>volume0</volume>
</root>
<root>
<journalTitle>Dixit</journalTitle>
<sourceType>JA</sourceType>
<title>title1</title>
<volume>volume0</volume>
</root>
<root>
<journalTitle>Singla</journalTitle>
<sourceType>JA</sourceType>
<title>title1</title>
<volume>volume0</volume>
</root>
CTS Query :
cts:search(
fn:doc(),
cts:field-value-query("Sample","######*()", ("unwildcarded")),
"unfiltered"
)
On running this query I am getting all the documents.
As per my understanding, it should return an empty sequence.
please find below the field I have created.
Field (in XML format) :
<field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://marklogic.com/xdmp/database">
<field-name>Sample</field-name>
<field-path>
<path>/root/journalTitle</path>
<weight>1.0</weight>
</field-path>
<word-lexicons/>
<included-elements/>
<excluded-elements/>
<tokenizer-overrides/>
</field>
Index setting:
If I will add any alphabet(s) in the search string it will give me the correct results.
Like:
##$%F
=====S
df===$d
Please help me to resolve this issue?
Try passing "exact" as an option to cts:field-value-query:
cts:search(
fn:doc(),
cts:field-value-query("Sample","######*()", ("exact")),
"unfiltered"
)
MarkLogic has an index for exact values to help in cases like this. Note it's only on when you have both case sensitive and diacritic sensitive indexes enabled (which you do). I know this works for cts:element-value-query so I expect it will for cts:field-value-query as well.
Use instead the 'exact' option in the field-value-query.
This requires the fast diacritic- and case-sensitive options, but you already have those enabled.
You can also try xdmp:plan before and after using 'exact' to see the effect on the query plan.
In the 'tokenizer overrides' option for your field, add these special character(#,=,#,$,%,^,*) as words (select 'word').
These special characters are not considered for matching by default. You need to override the default tokenizer to include them as words.
May I know what output are you expecting on passing this cts:element-word-query(xs:QName("journalTitle"),"=====S") for the above given for xmls.
Changing the one character searches to true in database config, resolves the issue in element-word-query.

FetchXML next page results

I want to populate a grid with data from Dynamics CRM. I use fetchXML, to get for each page 10 records. I want to get to the next page, to retrieve the next 10 records. But this isn't happening, I'm using XRMToolbox to simulate the fetch query but it returns me the same results, regardless of the page attribute value.
The fetchXML query is:
<fetch version="1.0" output-format="xml-platform" mapping="logical" count="10" page="1" aggregate="true" distinct="false" >
<entity name="webpage" >
<attribute name="url" groupby="true" alias="url" />
<attribute name="webpageid" aggregate="count" alias="top" />
<order descending="true" alias="top" />
</entity>
</fetch>
If I change the page attribute value, say to 10 the response won't be different.
Can anyone help me with this?
UPDATE
After many tests with XRMToolbox I've come to conclusion that this query won't listen, whatever page I provide to it. This is because of the aggregate attribute. If I remove it and of course remove the count aggregate, then changing the page attribute will actually fetch for me the next page results.
So in summary page attribute doesn't like the aggregate attribute. Maybe this can work with paging cookies, but I haven't tested it yet, I will test it and update this post.
To implement paging you need to use not only page number/records per page attributes but paging cookie as well. This msdn article provides all code you need to implement paging.

Mybatis: How can I get the first element from the passed parameter?

Given that my parameterType is an ArrayList, is it possible to get the first element from that list and use it in the where clause ?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="db">
<select id="selectFlag" resultType="java.lang.Boolean" parameterType="java.util.ArrayList">
select TOP 1 'true' from customers where id = ???
</select>
</mapper>
If your query uses one id, why are you sending a list and then picking the first one for the query?
Change your parameterType to an int (or whatever type the id has), don't send a list. This is a simple approach that also conveys the information that you are only retrieving data based on a single id. Your condition then changes to something like:
where id = #{id}
If you must absolutely send an ArrayList (for whatever reason) then MyBatis supports OGNL expressions so something like this should work:
where id = #{list[0]}
Unfortunately MyBatis lacks on the documentation side, so you can find out about things like this only by looking at the source code.