In VersionOne REST API how does one use multiple “with” statements with multiple “Where” clauses? - api

With the following query:
Base-URL/rest-1.v1/Data/Epic?sel=Category.Name,Custom_RoadmapInOut&where=Number=$numbers&with=$numbers=E-05322%2CE-05280%2CE-05616%2CE-04942%2CE-04921
I am getting the following response:
<Assets total="5" pageSize="2147483647" pageStart="0">
<Asset href="End-of-Base-URL/rest-1.v1/Data/Epic/138904" id="Epic:138904">
<Attribute name="Category.Name">Business Objective</Attribute>
<Attribute name="Custom_RoadmapInOut">2</Attribute>
</Asset>
<Asset href="End-of-Base-URL/rest-1.v1/Data/Epic/139078" id="Epic:139078">
<Attribute name="Category.Name">Initiative</Attribute>
<Attribute name="Custom_RoadmapInOut">1</Attribute>
</Asset>
<Asset href="End-of-Base-URL/rest-1.v1/Data/Epic/147147" id="Epic:147147">
<Attribute name="Category.Name">Parent Story</Attribute>
<Attribute name="Custom_RoadmapInOut"/>
</Asset>
<Asset href="End-of-Base-URL/rest-1.v1/Data/Epic/148702" id="Epic:148702">
<Attribute name="Category.Name">Parent Story</Attribute>
<Attribute name="Custom_RoadmapInOut"/>
</Asset>
<Asset href="End-of-Base-URL/rest-1.v1/Data/Epic/156961" id="Epic:156961">
<Attribute name="Category.Name">Milestone</Attribute>
<Attribute name="Custom_RoadmapInOut"/>
</Asset>
</Assets>
I want to limit the results to only return those assets that have a "Category.Name" of either "Business Objective" or "Initiative" and from those types to only return the ones that have a "Custom_RoadmapInOut" set to between 1 and 99.
What do I need to add to the query to have VersionOne do the heavy lifting and return only the desired items?
I am thinking I should be able to also add:
Category.Names=$names&with=$names=Business+Objective%2CInitiative
to the query and another where part to check the Custom_RoadmapInOut but I am not sure how to do this.
Currently I am making multiple queries and then using my own code to go through the results and keep only the ones that I desire to see.
Thanks for any help that can be provided.
Doug

Multiple with values can be separated by | (pipe). If you need more details than are shown in the documentation, you can try reading the grammar.
Multiple where filter tokens must be joined by logical operators. Logical and is ; (semicolon). Logical or is | (pipe). Again, the documentation can be a little sparse so you might try reading the grammar.
If you still find yourself still needing to run multiple queries to get what you need, you may find it advantageous to convert to the query.v1 endpoint.

Related

XPath using Get data from XML - Pentaho

I am calling Xero's API and then, using Get data from XML step. How can I extract Depreciation Expense - 218.8? I've tried /Rows/Row/Cells/Cell/Attributes/. and Rows/Row/Cells/Cell/Value - among other options but they didn't work. And another question, if I have multiple accounts and I need to extract exactly 'Depreciation Expense', I've tried playing with [] to extract Nth element but somehow it didn't work. Is it Pentaho specifics?
<RowType>Section</RowType>
<Title>Less Operating Expenses</Title>
<Rows>
<Row>
<RowType>Row</RowType>
<Cells>
<Cell>
<Value>Depreciation Expense</Value>
<Attributes>
<Attribute>
<Value>f14d778f842543feafca2fdcf0437cf7</Value>
<Id>account</Id>
</Attribute>
<Attribute>
<Value>f14d778f842543feafca2fdcf0437cf7</Value>
<Id>groupID</Id>
</Attribute>
</Attributes>
</Cell>
<Cell>
<Value>218.16</Value>
<Attributes>
<Attribute>
<Value>f14d778f842543feafca2fdcf0437cf7</Value>
<Id>account</Id>
</Attribute>
<Attribute>
<Value>f14d778f842543feafca2fdcf0437cf7</Value>
<Id>groupID</Id>
</Attribute>
</Attributes>
</Cell>
</Cells>
</Row>
With complex XML structures like this one, it's often best to use nested Get Data from XML steps in Pentaho.
In your sample (which misses a root element and closing /rows btw) it looks like the XML represents an Excel-like "rows with cells" structure. The cells likely belong to a column depending on their order. For this answer, I'll assume this order is indeed fixed in the XML and there are no missing cells. Verify that!
The first XML step should extract each XML "row" into a Pentaho row and give back the XML node, not just a value. For that, you can use the Loop XPath setting /YourRoot/Rows/Row and get a field with XPath "Cells" and Result type "Single node". Including a rownum field might be nice, select that option if you need it.
The second XML step can then use the output field from the first, extracting from Loop XPath /Cells/Cell and getting all the fields you need using the Get Fields button.
Once you have the fields, use a Select Values step to remove the original XML fields, then use a Row Flattener (only works for fixed Cell order).

Document id reference desn't work for impex

I have a problem with impex which contains document id reference.
From docs:
"Especially for importing partOf item values it is necessary to reference these items by means other than the usual unique column technique because partOf items often do not provide a unique key but only hold their enclosing parent as foreign key."
Items from *items.xml (only the most important parts)
<itemtype code="A" autocreate="true" generate="true" abstract="true"/>
<itemtype code="B" autocreate="true" generate="true" extends="A">
<deployment table="btable" typecode="20115" />
<attributes>
<attribute qualifier="code" type="java.lang.Integer" autocreate="true" generate="true">
<persistence type="property"/>
<modifiers optional="false"/>
</attribute>
</attributes>
</itemtype>
<itemtype code="C" autocreate="true" generate="true">
<deployment table="ctable" typecode="20117" />
<attributes>
<attribute qualifier="code" type="java.lang.String" autocreate="true" generate="true">
<persistence type="property"/>
<modifiers optional="false" unique="true"/>
</attribute>
<attribute qualifier="test" type="A" autocreate="true" generate="true">
<persistence type="property"/>
<modifiers optional="false" partof="true"/>
</attribute>
</attributes>
</itemtype>
Impex code:
INSERT B;code;&docIdRef
;1;docId
INSERT_UPDATE C;code[unique=true];test(&docIdRef)
;uniqueCode;docId
Error message:
cannot create C with values ItemAttributeMap[ registry: null, type: <null>, (...) due to [de.hybris.platform.servicelayer.interceptor.impl.MandatoryAttributesValidator#3b777877]:missing values for [test] in model C
When I removed 'partof' modifier from 'test' attribute (C class) everything worked fine.
I wonder how impex should looks like if i want to keep 'partof' modifier.
When you use partOf you must reference the partOf using the owner.
So it does :
INSERT B;owner(C.code);&docIdRef
;uniqueCode;docId
INSERT_UPDATE C;code[unique=true];test(&docIdRef)
;uniqueCode;docId
You don't need to assign B an identifier, you just need to reference the owner.
If you know for sure that your data is correct you can use [forceWrite=true] modifier or legacy mode to skip service layer validation.
You should also make sure that this configuration is what you really need. Setting either optional to true or partOf to false or providing default value should fix the issue as well.
Since you have mentioned partof="true" you can not assign a reference of type A. You can only create a new entity.
Check the OOTB AbstractOrder2AbstractOrderEntry relationship, they have mentioned partof="true" for AbstractOrderEntry means you can't reference any other AbstractOrderEntry to Order. You can always create new entry.
Have a look at HMC site as well
You can see here there is no + Add Entry button available here. The reciprocal can be possible.

case statement inside of fetchxml script

Please note that although this question is an entirely different question, it relates directly to this question.
The following is the script that returns the dataset for my SSRS chart:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" aggregate="true">
<entity name="account">
<attribute name="bio_employeesworldwide" alias="TotalWorldWideEmployees" aggregate="sum" />
<filter>
<condition attribute="customertypecode" operator="eq" value="2" />
</filter>
<link-entity name="contact" from="parentcustomerid" to="accountid" alias="contact">
<attribute name="bio_webuseraccountstatus" alias="count_bio_webuseraccountstatus" aggregate="countcolumn" />
<attribute name="bio_webuseraccountstatus" alias="bio_webuseraccountstatusgroupby" groupby="true" />
</link-entity>
</entity>
</fetch>
The values for bio_webuseraccountstatus can be Active, Inactive, Disabled, Pending, etc..
In FetchXML is there a way to do a case statement where you "InActive" for every value that is not equal to "Active" ?
As you can see I've been trying to solve this issue within the reporting layer, but am experiencing lots of "string format" issues.
Can this be done with the dataset layer (fetchxml) instead?
According to this Microsoft forum post:
There's no equivalent function in FetchXml. Instead, you will need to return each field value, and process the CASE logic in the calling code. If this FetchXml is to be used in a report, then you may be able to implement the CASE logic in a calculated field on the report.
You can always parse the output of the fetchxml on return.
So rather than pushing to the screen, report, or db, the original record field of isreceivetravelalerts, you check the status (zero or one) and rewrite it, and add the new variable to your output. Clunky, but useful.
if ($record->isreceivetravelalerts == 1)
{
$travel_alerts = "Active";
}
$travel_alerts = "Inactive";

FetchXML nvarchar returns nothing - Custom Report for CRM

I am trying to get data from Dynamics CRM 2013 for a custom report using FetchXML.
I "converted" the following SQL Query to FetchXML using this page: http://www.sql2fetchxml.com/
SQL:
SELECT
accountidname,
billto_line1,
billto_postalcode,
billto_city,
invoicenumber,
name,
description
FROM FilteredInvoice
WHERE invoiceid = #invoiceid
FetchXML:
<fetch mapping="logical">
<entity name="invoice">
<attribute name="accountidname" />
<attribute name="billto_line1" />
<attribute name="billto_postalcode" />
<attribute name="billto_city" />
<attribute name="invoicenumber" />
<attribute name="name" />
<attribute name="description" />
<filter>
<condition attribute="invoiceid" operator="eq" value="#invoiceid" />
</filter>
</entity>
</fetch>
Both, "accountidname" and (e.g.) "billto_line1" are NVARCHAR(4000) and both contain data, but if I try to execute the query (e.g. in the "Query Designer" in Visual Studio) only the data of "billto_line1" is shown, not the data of "accountidname".
Since both fields "accountidname" and "billto_line1" are of the same type (nvarchar(4000)) and contain information in the database (I checked it with the "Microsoft SQL Server Management Studio") I am wondering why I can only receive the information from one of those two.
This has happend with many different fields of the type NVARCHAR - some are displayed correctly, while some are not - and I have no idea why.
I would be very pleased if somebody could give me a hint :)
Thank you
accountidname is on the Views, not the actual tables, in SQL. It is not a field on the invoice entity and therefore will not return any information in a FetchXml request.
You should be able to retrieve the Account's name by using accountid - I don't remember in SSRS how the Name property of an EntityReference is surfaced but it should be available.
The FetchXml converter is good at converting SQL SELECT's to FetchXml format and converting joins. It will not validate that the SQL fields are available in FetchXml - that could only be done by accessing the metadata of the CRM Org.

How to add Link to Story via VersionOne REST API?

I'm able to create new Story via POST to /VersionOne/rest-1.v1/Data/Story with corresponding XML payload. Setting all attributes (including relational) works like a charm. However I'm unable to figure out how to add a Link asset to the Story asset.
When I try POSTing to /VersionOne/rest-1.v1/Data/Link with following XML payload:
<Asset href='/VersionOne/rest-1.v1/New/Link'>
<Attribute name='AssetType' act='set'>Link</Attribute>
<Relation name='Asset' act='set'>
<Asset href='/VersionOne/rest-1.v1/Data/Story/123' idref='Story:123'/>
</Relation>
<Attribute name='OnMenu' act='set'>true</Attribute>
<Attribute name='URL' act='set'>http://my.example.com</Attribute>
<Attribute name='Name' act='set'>My Link Title</Attribute>
</Asset>
The server however returns:
<Error href="/VersionOne/rest-1.v1/Data/Link">
<Message>Violation'Readonly'Link.AssetType</Message>
<Exception class="VersionOne.DataException">
<Message>Violation'Readonly'Link.AssetType</Message>
</Exception>
</Error>
Seems like adding links is prohibited but actually I can add Links via the standard web interface without issues.
My original idea was to create Link asset first and then update the Story with respective relational attribute pointing to that Link asset.
Any ideas anyone?
Thanks!
(I'm using JavaScript/jQuery)
My bad. The <Attribute name='AssetType' act='set'>Link</Attribute> attribute in the POST payload is obviously wrong - it is trying to set the asset's type (link) which does not make sense since I'm stating the type in URL already. It works perfectly without the attribute (as expected).