0

When user opens a new case, I need to check if the serial number of the new case already exists in order to change the priority of the case. I use Kaskela's solution to do this and I think the best way to do it is to use query to get a single value (what I actually want to get is a true or false boolean)

this is the fetchXML I use

<fetch mapping='logical'>
  <entity name='case'>
   <attribute name='title'/>
     <filter type='and'>
        <condition attribute='abc_serialnumber' operator='eq' value='DYN_serialnumber' />
     </filter>       
  </entity>    
</fetch> 

I get the error

An exception System.FormatException was thrown while trying to convert input value 'SN00105GH' to attribute 'case.abc_serialnumber'. Expected type of attribute value: System.Guid. Exception raised: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

I get that it needs serial number's GUID which I can't use since it is in another entity.

I have two questions: Is query to get a single value the proper way to achieve what I want? Why does it need GUID?

Arun Vinoth
  • 20,360
  • 14
  • 48
  • 135
Morgana
  • 155
  • 3
  • 17

1 Answers1

1

What I understand is, abc_serialnumber is a lookup in case record, so it will be always a GUID - 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). The value you are passing as DYN_serialnumber is SN00105GH but the system cannot do this comparison - GUID with a string. Hence the error.

If you know the value (ie SN00105GH) always, then you have to do another fetch based on this value from abc_serialnumber entity and then pass the retrieved serial number record GUID into your above query. That will give you the case associated with the assigned serial number wrt passed value.

Or else, you have to do linked entity in fetchxml to get the case joined with serial number that filtered by value in single query.

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" >
  <entity name="case" >
    <attribute name="title" />
    <link-entity name="abc_serialnumber" from="abc_serialnumber" to="abc_serialnumberid" link-type="inner" alias="ac" >
      <filter type="and" >
        <condition attribute="abc_name" operator="like" value="SN00105GH" />
      </filter>
    </link-entity>
  </entity>
</fetch>

If the query result count from the query is greater than zero, then the result is true. Otherwise false.

Arun Vinoth
  • 20,360
  • 14
  • 48
  • 135
  • Thanks for your answer. I tried the fetchXML with link-entity but I get the error 'Case' entity doesn't contain attribute with Name = 'abc_serialnumberid' and NameMapping = 'Logical', which is true because 'abc_serialnumberid' belongs to 'abc_serialnumber' entity. Any further help would be greatly appreciated – Morgana Jul 16 '20 at 07:25
  • 1
    @Morgana, probably it should be `abc_serialnumber` instead of `abc_serialnumberid` – Arun Vinoth Jul 16 '20 at 13:31