How to actual value of field type like OptionSet, Status, State using OData query in MS CRM? - dynamics-crm-online

I am working on some functionality and I want to get value of some fields whose type like OptionSet, Status, State etc. When I am trying to get value of it, I am getting value in numbers like 0 and 1.
i.e. https://xxxxxx.crm.dynamics.com/xrmservices/2011/OrganizationData.svc/InvoiceSet
When I fire above query and get data, data of OptionSet types is in numbers where actual data is different. Same way when I try to get Status Code whose type is Status, it returns value like 0 and 1. The actual value is "Active".
Can anybody suggest me how to get value of this such fields?

Just FYI. 0, 1 and other integers are real values. Active, Inactive and other - are labels. If you want to get labels along with int values you will have to switch to SOAP and use FormattedValues collection that will contain label of correspond field or to WebApi - http://himbap.com/blog/?p=2077

Related

Distinct values for SSRS Parameter when query returns Duplicates

I have a parameter that receives his values from a dataset, but I receive multiple instance of the same value and I need to filter those in order to have only 1 occurence per value. I cant seem to find where I can manually edit the query.
This is what I get when I select Report Parameter Properties / Available Values / Get values from a query.
How can I filter it so I only get 1 of each which would make it easier for the user when I what to select what he wants to see from the report.
Thank you

Kentico 12: change value of one page type field based on value of another field

I have a custom page type with two fields, StateName and StateCode. I would like it so that when a value is selected in either of these fields, the other field’s value changes to match.
So for example, if I select “Alabama” in the StateName field, the value of the StateCode field would automatically change to “AL.” Or if I select “CO” in the StateCode field, the StateName field would automatically change to “Colorado,” etc. Is this possible?
(I have to keep these as two separate fields, because I need to display either the state name or the state code on the front-end depending on context. Therefore, I can’t use a single field with options like AL;Alabama because then the field only returns the value AL and I have no way of getting the display name Alabama).
I know Kentico has options for setting “dependent” fields, but that only appears to determine visibility – e.g. only display Field B if I select a particular value in Field A. I can’t find a way to actually change the selected value in one field based on the selected value in another field.
Two control solution seems some kind of an overkill here. You can use StateInfoProvider to get what you want.
StateInfo state = StateInfoProvider.GetStateInfo("Alabama")
The other way would be to use a simple drop down control and use
query like that :
select stateCode + '|'+ StateDisplayName, StateDisplayName from cms_State
to get get code and display name as value separated by |

retrieve a record using Dynamics 365 Web API with empty alternate key

Problem
I'm trying to query records from Dynamics 365 using the Web API where a key attribute is null.
Approach
For testing purposes I created an entity with a string attribute, an integer attribute, and a decimal attribute. I then created an alternate key and put those three attributes in it, making this combination of attributes unique. I then created some records.
Querying the data using the Web API works as expected. I created a record with those values:
{
"my_string_key": "s1",
"my_integer_key": 1,
"my_decimal_key": 1.23
}
And query it like this:
/my_entities(my_string_key='s1',my_integer_key=1,my_decimal_key=1.23)
This returns the desired record.
However I can't get it to work when any of the key fields is empty, it always returns a 400 with message "Bad Request - Error in query syntax". Just for clarification: I purposely created records where one of the key attributes is empty, like this:
{
"my_integer_key": 1,
"my_decimal_key": 1.23
}
{
"my_string_key": "s1",
"my_decimal_key": 1.23
}
{
"my_string_key": "s1",
"my_integer_key": 1
}
Notice how each record is missing one of the key attributes, which effectively leaves it at null.
I tried using =null, =empty, ='', = and =Microsoft.OData.Core.ODataNullValue but nothing works. I tried to query them like this:
/my_entities(my_string_key=null,my_integer_key=1,my_decimal_key=1.23)
/my_entities(my_string_key='s1',my_integer_key=null,my_decimal_key=1.23)
/my_entities(my_string_key='s1',my_integer_key=1,my_decimal_key=null)
I also tried omitting the attribute with null in it, like this:
/my_entities(my_integer_key=1,my_decimal_key=1.23)
/my_entities(my_string_key='s1',my_decimal_key=1.23)
/my_entities(my_string_key='s1',my_integer_key=1)
None of this works. Can anyone provide a solution?
Final Words
I know that key attributes shouldn't be empty because that's not the point of key attributes. My scenario however requires to handle this specific case.
I also know that I could just use the $filter parameter, but I'd like a solution without having to resort to this "workaround". After all, it is a key and I'd like to treat it as one.
I think your efforts prove that key attributes cannot be empty. So, time for another approach.
Create a custom attribute and fill it with the combined values of the three key attributes. You can do this in a plugin registered in the pre operation stage of the Create and eventually Update messages of your entity.
Use the custom attribute as the key attribute.

Live field update in form in Access 2013

So I'm somewhat new to access 2013, anyways, I've created a form in access 2013 based directly off a table, so no queries involved if that matters, and what I'm trying to do is just have a text box that updates the total value of 3 different fields as they're entered.
right now it's just a plain-text box, the control source is "=[Search Cost]+[Update Cost]+[Copy Cost]", and if I close the form entirely and reopen the record it updates the text box with the total for all three, but the customer wants it to update in real time. Any suggestions?
I just tried your scenario in Access 2013 on a simple form and it updated for me in real time as I entered values. However, that was because each of the three fields values had a Default Value of 0 in my test table.
So I suspect this is not updating for you in real time because one or more of those values is null while you are entering data in the form. Access doesn't know what [Some field value]+Null should be (it's an unknown thing) so it won't display a calculated value in real time on your form until you provide a value for each of the three fields.
So how can you get around this?
You can add a Default Value of 0 or some other value to each of the three fields at the table level.
Or you could modify your form expression to use the NZ function which will convert any null values to zero. So use this expression:
=Nz([Search Cost])+Nz([Update Cost])+Nz([Copy Cost])
Either of those options should achieve your end goal I believe. They did in my quick tests.

ServiceNow Encoded Query validation

I intend to let users specify encoded query in ServiceNow SOAP requests.
The problem is that if user specifies invalid query string (e.g. "?##" or "sometext"), ServiceNow do not return any exception, but every row or no rows at all.
Is there a way to check validity of encoded query via webservice?
Fandic,
If you know ahead of time which table the SOAP query will be running against (or can get that information from the user when they submit the query) you can set up your own web service exclusively for checking the validity of a query string.
GlideRecord has the "addedEncodedQuery" method for putting in encoded queries, and it has a getEncodedQuery for turning the current query into an encoded string. If you instantiate a GlideRecord object, and pass it an invalid query string like this:
var myGR = new GlideRecord('incident');
myGr.addEncodedQuery('invalid_field_foo=BAR');
You can then call getEncodedQuery out to see if it is valid:
var actual_query = myGR.getEncodedQuery(); //sys_idNotValidnull
You shouldn't do simple comparison between the input and the output, as the API doesn't guarantee that a valid query will be returned as the exact same string as entered. It's better to simply validate that the actual_query does not equal 'sys_idNotValidnull'.
I always recommend enabling the system property 'glide.invalid_query.returns_no_rows' to avoid this effect. The property does just what it says. I never understood why you'd ever want to return all rows for an invalid query. I've seen a number of cases where developers had a query defect and never knew it since rows were coming back.
You can use the below code so that query will return the result only when it correct.
gs.getSession().setStrictQuery(boolean);
This overrides the value of system property :
glide.invalid_query.returns_no_rows
Reference : https://docs.servicenow.com/bundle/istanbul-platform-administration/page/administer/reference-pages/reference/r_AvailableSystemProperties.html
Check the property value glide.invalid_query.returns_no_rows. If it's true, the invalid query returns no rows. If false (or not available) it is ignored.
This can be overridden with gs.getSession().setStrictQuery(boolean); on a script-by-script basis.

Resources