Simple formatted search

Hi,
I'm trying to learn how to use formatted searches and SQL in SAP Business One. Can anyone give me some simple examples to start with?
For example, on AR Invoice, if customer (OINV cardcode) is X, a UDF field should be populated 'Y". If customer (OINV cardcode) is not X, UDF field should be populated 'N'.
Can you provide me the SQL code for the query to be used in the formatted search? Just looking for some examples to get started.
thanks

Thanks Gordon, that worked!
How do you know that $[$4.0.0] is OINV,cardcode(BP name on AR invoice)?
For example, if I want to use a different field intead (like Item No.) how do I know the paramater/variable to sue?
I guess $[   ]  means a user input paramater(not yet saved to database)?

Similar Messages

  • Decimal and formatted search

    hello,
    I've defined an UDF as Price.
    Number of decimal for prices is set to 3 in the general settings.
    the actual result of my formatted search is rounded to 2 decimals although 3 decimal are displayed.
    here is a simple formatted search that illustrate the issue :
    SELECT 100 / (100+19.6)
    the displayed result is 0.840 instead of the correct value : 0.836
    How can It be solved ?
    Best regards,
    Francis

    Hi
    Please check the decimal settings of
    amount as well(general setting -display tab)
    there is one case:
    When under Adminstration -> System Initialization -> General Settings ->
    Display, the decimal for the amount is defined as 0 and the UDF is
    defined as eg.  alphanumeric or units and total amount, The UDF does not
    return the decimals and round the amount.
    base on my testing:
    if I define 2 decimal places for amount
    then the UDF result  will be 0.84
    But if I define 3 decimal places for amount
    then the UDF result will be  0.83
    Best Regards
    Helen Sun

  • Authorizations for formatted searches?

    Hello experts,
    I have created a simple formatted search so users select from the list the country of origin of a batch.
    Currently, they get an error message.
    Do you know which authorizations I should give them so they can use that formatted search query?
    Many thanks

    Hi Pam,
    In Authorisation window for the particular user who is facing the error.
    Navigate Admin > System initilisation > Authorisation > ( Select ) >
    Reports --> Query Generator -->  Execute Non - Select SQL Statement  and give  Full Authorisation.
    Is the User now able to execute FMS ?
    Regards,
    Rakesh N

  • Problem with activation of Formatted Searches

    There seems to be an error in the activation of formatted searches in SAP B1.
    The following is an example to demonstrate the real situation with a minimum of complexity.
    1. We have defined 2 user defined fields, U_trigger and U_target, in the title area of documents. Both are defined as alphanumeric fields with standard length 10 and some predefined values.
    2. For sales orders we have defined for UDF 'target' that a formatted search 'getTriggerValue' is activated on changes of UDF 'trigger'.
    3. The formatted search 'getTriggerValue' reads the value of UDF 'trigger' and writes it to UDF 'target':
    DECLARE @triggerValue AS nvarchar(10)
    SET @triggerValue = $[ORDR.U_trigger]
    SELECT @triggerValue
    When we add a new document to the database, i.e. the document is in "button-mode" = 'add', there are no problems with the activation of the FS on field 'target' when the value of field 'trigger' is changed!
    After a document is already written to the database and is later displayed on the screen again, the document is in "button-mode" = 'OK'. In this situation the FS on field 'target' IS NOT ACTIVATED when the value of field 'trigger' is changed, i.e. the value of 'trigger' is not copied to 'target'.
    After this first change the document is now in "button-mode" = 'update'. If we now change the value of field 'trigger' a second time the FS on field 'target' is activated an the value is copied from 'trigger' to 'target'.
    If we define the FS of field 'target' with option 'Refresh Regularly' the FS is activated after the first change of field 'trigger' as expected.
    But we CAN NOT USE THIS OPTION AS A STANDARD SOLUTION for our problem, since some fields and their FS can not work with this option and need the standard option 'Display Saved Values' set. Otherwise some fields yield wrong values, since they are working not only with constant predefined values as in the simple example above, but with dates which are set by GETDATE() in the FS, e.g.
    Is this behaviour a bug of SAP (FS is not activated even if the value of the refresh field is changed)?
    If not, what is the idea behind this behaviour?
    And how can I get around this behaviour?
    Thank you for your support!
    Frank Romeni

    Hello Suda!
    Many thanks for your answer!
    Perhaps my explanations are a bit in confusion.
    The example in my question is just to demonstrate the behaviour of the formatted search with option 'Display Saved Values' set, i.e. in a document that is already saved to the database, only after the second change the formatted search is activated.
    I am aware that with the simple formatted search that I have shown as an example everything works fine with the option 'Refresh Regularly'.
    But what is the meaning to activate the formatted search only after the second change when option 'Display Saved Values' is set?
    The reason why we can't use option 'Refresh Regularly' is that in our real application not only constant values are copied from 'trigger' to 'target'.
    Let me give you an example which approaches the real situation more than the first example:
    DECLARE @trigger AS nvarchar(20)
    SET @trigger = $[ORDR.U_trigger]  -- U_trigger / UDF 'trigger'
    DECLARE @save AS datetime
    SET @save = $[ORDR.U_date]        -- U_date / UDF 'date'; save current date
    IF @trigger = 'getDate'
      SELECT GETDATE()
    ELSE IF @trigger = 'getDateConst'
      SELECT '01.01.2008'
    ELSE IF ...
    ELSE
      SELECT @save                    -- no value in @trigger to change date ==> reset
    Option 'Display Saved Values' set: formatted search is activated only after the second change of value of UDF 'trigger'. This is not acceptable!
    Option 'Refresh Regularly' set: Suppose the 'trigger' is set to 'getDate'. The actual date, e.g. 25.06.08, is displayed in UDF 'date'. The document is saved to database. When the document is fetched again on the next day, the formatted search is activated immediately without the change of any values, i.e. 'trigger' still is set to 'getDate'. This is evaluated in the formatted search and the function GETDATE() is called and the now actual date, 26.06.08, is written to UDF 'date'. This is wrong!
    I hope that the new example shows why we can't use option 'Refresh Regularly'!
    We need no regularly refreshed value of UDF 'date', we need an activation of the formatted search only when the value of UDF 'trigger' changes. But why is it activated only after the second change when 'Display Saved Values' is set?
    Thank you for further support!
    Frank Romeni

  • Formatted search - syntaxhelp

    Dear All,
    i want to create a very simple formatted search, which updates the unitprice-field in sales order when itemcode changes.
    With the actual cardcode number and itemcode of the sales order (before saving) i want to check my udt (specialprice) for a fitting entry and want to return a price out of this udt.
    My FS:
    SELECT
          T0.U_SpecialPrice AS [Specialprice]
        FROM
          [@XXX_SPECIALPRICE] T0
        WHERE (T0.U_CardCode = $[$4.0.0] AND T0.U_ItemCode = $[$38.1.0])
    If i replace the $-Codes with a test-value the fs works. The udf's have the necessary types and digits.
    The error-message can't help me:  incorrect syntax near '$4.0.0'
    Thank you for your answers...
    GB

    hmmm.... I don't think so, because i have a more complicated query in purchase order which does nearly the same and this works....ok there is no direct where-condition with the udt-colums but an inner-join...
    SELECT
          T4.U_SpecialPrice AS [Specialprice]
        FROM
          OPOR T0 INNER JOIN
          POR1 T1 ON (T0.DocEntry=T1.DocEntry) INNER JOIN
          RDR1 T2 ON (T1.BaseEntry=T2.DocEntry AND T1.BaseLine=T2.LineNum AND T1.BaseType=T2.ObjType) INNER JOIN
          ORDR T3 ON (T2.docentry=T3.DocEntry) INNER JOIN
          [@XXX_SPECIALPRICE] T4 ON (T3.CardCode=T4.U_CardCode AND
          T2.ItemCode=T4.U_ItemCode)
        WHERE (T0.DocNum=$[$-8.0.0] AND T1.LineNum=$[$38.0.0]-1)

  • Formatted Search is driving me crazy - Customer Reference Number to UDF

    Hi all, what should of been a simple Formatted search has turning into a monstrosity.
    All I am trying to do is to copy my Customer Reference Number on a Sales Order Header, to a Header UDF, via Formatted Search. Here is my formatted search:
    SELECT $[$14.0.0] FROM ORDR T0
    That formatted search is connected to my UDF also at the sales order header level.
    Any ideas as to why this formatted search does not duplicate the customer reference number into my UDF?
    I am running 2007A SBO.
    Thanks guys.
    Mike
    Formatted search is: SELECT  Dollar[Dollar14.0.0]
    For some reason, this forum changes my SQL sentence into a URL.
    Let me try this again. SQL statement is SELECT DollarBracketDollar14.0.0Braket

    Hi Mike,
    Try this,
    ->> Create 1 UDF in Title(Header) Level on Sales Order(Marketing Documents).
    ->> UDF :
    Type - Alphanumeric.
    Length - 100. (because in SO Customer Reference Number Field Character is 100 in Table)
    Structure - Regular.
    ->> Assign the below FMS Query in UDF.
    ->> Autofresh of Customer/Vendor Ref. No..
    Ex.
    1. Goto the UDF and Clcik (ShiftAltF2).
    2. Select the SEARCH BY SAVED QUERY.
    3. Assign the FMS Query.
    4. Select the AUTO REFRESH WHEN FIELD CHENGES.
    5. Select Customer/Vendor Ref. No..
    6. Put the Tick Mark in Display Saved Values.
    SELECT $[ORDR.NumAtCard]
    or
    SELECT $[$14.0.0]
    Regards,
    Madhan.

  • Query - Formatted Search in a User Defined Field

    Hi,
    I am having some problems with a very simple query but it doesn't seem to work. I insert this formatted search in to my UDF I made called Cost. The query I am using is:
    SELECT  $[$34.0.0] - (I had to use variable number because this Unit Price field in the Item master data does not have a field name associated)
    It is supposed to grab the unit price from the screen, however it is always displaying zero when I query it, and when I put it in the UDF as a formatted search, it give me the internal error.
    I would greatly appreciate your help.
    Thanks

    Question 1: Where is this Cost UDF defined.  Is it at the Marketing document Header or row level?
    NOTE:
    The field reference for the Unit Price column is incorrect.  When you mouse over the Unit Price column you should see the values for Item=xx  Colunm=xx
    The syntax is $\[$Item.Column.Type].  Therefore for your case it should be $\[$38.14.Number]
    The type prefix can be 0 if you are accessing a Alphanumeric column.
    If you user field is at the Header level the Formatted Search Query might not work unless you highlight that whole row and then click on the header level UDF and press Shift+F2
    How have you set the refresh options?

  • How to Fetch the Row value in SBO Formatted search

    Hi Experts,
    I have created a Sales order, in which i  have 4 UDF Fields(A,B,C,D) in the following:
    Example values:
    A  B  C  D 
    2   2   4  4
    3   2   6  10
    C=A*B
    D=1st value of D + 2nd col value of C
    i have written query for C, but how to write the Formatted search Query for generation of D values. plz reply as soon as possible.

    Magesh,
    I quite understand what you are trying to do.   If you look at the example below I added a third row to show how you want the D to be a running total of column C. RIGHT !!
    A B C D
    2 2 4 4
    3 2 6 10
    <b>4 2 8 18</b>
    Honestly, it is not going to be simple as you do not have a way in SBO to access a particular column from a row.  When you say $[$38.U_C] it refers to the context row OR the row which has the highlight OR the row which has the curson on it.
    It is not possible to say $[$38.U_C from row 2]  JUST  NOT POSSIBLE ...
    You have to write a tricky code by using a temp table referencing the value of column C.  Also you have to keep track if Rows gets deleted and a new row added. 
    I will test a sample code and will come back.
    Suda

  • Addition of two rows values in table  using formatted search

    hi all,
            i have created one UDF field in market document rows, now in AR invoice i need to add the values in the UDF fields of two rows, want to show it in anather outside UDF in title. kindly suggest me some query to track that.
    Ex:- i had entered two items in rows and
    for first UDF row i have given 20
    for second UDF row i have given 30.
    now i need to show sum of the two UDF in two rows in title UDF.
    kindly give me some query used for formatted search to do this task.
    regards
    sandip

    Sandip,
    To the best of myknowledge When you try to take the row value to the header the results of the Formatted Search are not consistent.
    but for your interest, I am giving below the logic to work this out.
    You need two Header level user fields.  One to copy the row user fields value and the other to store the sum.
    You can create a simple SQL "SELECT $[$38.U_UserFieldName] (substitute with row level user field name) and attach it to the first header level user field and make it Auto refresh on doc total.
    Then Attached SQL  "SELECT $[ORDR.U_HeaderUserField1] + $[ORDR.U_HeaderUserField2]"
    The results could be flaky because the header user field takes the value of the active row and sometime it only considers the first row active though you might be entering the second row of data.
    My recommendation would be to Use The Transaction Notification Stored Procedure for this by which you can be absolutely sure that the Header User field will have the sum.
    Let me know if you need directions for this.
    Regards
    Suda

  • Golden arrows in a formatted search

    Hi
    I have a simple query that works fine and returns the golden arrows so I can drill into the documents.
    I then created a header UDF on the sales order and put a formatted search on that field.  The formatted search is set to use that query with no auto refresh. So the user will come to that field and hit Shift F2.   That also works fine the problem is when the results pull up there the golden arrows are no longer there.  Is it possible to retain the arrows in this situation?
    Thanks.

    Jared,
    This is a shortcoming with Formatted Searches where the link arrow will be lost. 
    I am not aware if there is a way to retain the link arrow.
    Suda

  • How to Define and Use Formatted Search in Sap Business One 2007

    Hi
        Any Document on How to Define and Use
    Formatted Search in Sap Business One 2007.
    Thanks

    Hi Manish,
    It is Very simple Procedure of defining FMS(Formatted Search)
    in SAP 2007B Same as SAP 2005B & SAP8.8 Version
    Do this,
    ->> Open the require Document.
    for ex. IF you add the UDF in Marketing Document(Sales/Purchase)
    1. Goto the UDF (or) any Default(Original) Field and Click ShiftAltF2.
    2. Select the SEARCH BY SAVED QUERY.
    3. Assign the FMS Query.
    4. Select the AUTO REFRESH WHEN FIELD CHENGES.
    5. Select the require Auto refresh field
    6. Check the Refresh Regularly (or) Display Saved Values.
    Regards,
    Madhan.

  • Simple Site Search

    Anyone figured out how to add a simple site search to your web site using Google, Yahoo, or Bing.  The options out there using html coding do not seem to format correctly when added to an inserted object.

    Thanks I did look at it but found out that Google will give you an embedded search widget for free that links you in to their search results.  Thanks.
    Robert C. Whitehead
    <mailto:[email protected]> [email protected]
    <http://www.hilliardawilbanksfoundation.com/> eMail-Tag-Line3

  • Getting Error Message using Formatted Search

    Hi,
    I am using formatted search for validating a particular field, and that happens fine.  Kindly let me know if I can also display error messages using the same formatted search.
    If yes, what am I to include in the formatted search, and if No, please let me know the alternative.
    Thanks in advance.
    Satish.

    Hi Satish,
    if you validate the value of a field and intend to rise an error message on detection of invalid values in a separate window or in the status line there is no way to do it with Formatted Searches (as far as I know)!
    You could use the following methods as simple workarounds if you don't want to program a solution with the SDK:
    1. Solution
    You can display the text of an error message in the field you validate; of course, the invalid data then is overwritten with your error message, but you could construct the message from fixed text parts concatenated with the data found in the field.
    Be sure to save the original data of the field in your query before you do anything else. This way you sustain the field data in case the data is valid!
    Example:
    DECLARE @save AS ....
    SET @save = $[xxxxx]
    IF $[xxxxx] test on invalid data
      SELECT 'Error: Invalid data: ' + $[xxxxx] -- in case of error
    ELSE
      SELECT $[xxxxx] -- no error - sustain valid data
    END
    2. Solution:
    You define a sepate User Defined Field (UDF) for potential error messages - that's the way I often programmed it for our own applications. Suppose that the Formatted Search is connected to this UDF and the field to validate is field 'xxxxx'. The Formatted Search is triggered (auto-refresh) on change of field 'xxxxx':
    IF $[xxxxx] test on invalid data
      SELECT 'Error: Invalid data: ' + $[xxxxx] -- in case of error
    END
    May be that there are minor syntactical errors or missing type conversions in the code above - but I hope it gives you an idea on how to solve your problem without SDK programming!
    Good luck!
    Frank Romeni

  • Formatted Search Error -  Help Needed

    Hi All,
    My client has a peculiar purchase process. They are into chemical trading and do their purchase as follows:
    The vendor gives discount based on the volume and not on the quantities purchased. Thus, an item X if purchased in 250gm will cost $ 20 while the same item if purchased in 50gm may come to $15. So, the user wants to enter this values in the purchase order and want the unit price to be calculated based on this. Assuming the clients wants 1kg quantities of item X, he would like to fill  250 x gm  @ $20 in separate UDFs and based n these values, the system should calculate the unit rice for this item.
    What I did was as follows:
    a)  I created 3 UDFs each for the Base Quantity (U_BPQty), Base UoM(U_BPUnit),  Base Price (U_BasePrice). Thus the user enters 250, gm, 20 respectively as explained in the above example.
    b) I created one field  (U_UnitQty) to convert the base unit into purchasing unit. For this, I am writing a query to get the conversion factor value into the PO. Thus if the Purchasing UoM is KG and the base unit in which the supplier is charging is G, then I am populating 1000 in this field.   
    c) One more UDF to convert the base price into the unit price is captured is created. So, if 250gm cost $20 and my client wants 1kg, I am first getting the value of 4 in this UDF. This I am getting by dividing the value obtained from the step b) with the value in U_BPQty. 
    Once I get this value, I then calculate the unit price by multiplying 4 with $20 which will populate $80 in my Unit Price field through another FMS.
    I wrote a formatted search for converting this base unit to purchasing units. Given here is the FMS which is giving an error. For the sake of another functionality, I created a UDF for Purchasing UoM as well (U_UoM).
    Declare @UQty as varchar
    Declare @BPC as varchar
    set @UQty = $[POR1.U_UnitQty]
    set @BPC = SELECT
    (Case
    when $[POR1.U_UoM]  = 'kg' and $[POR1.U_BPUnit] = 'kg' then 1
    when $[POR1.U_UoM]  = 'kg' and $[POR1.U_BPUnit] = 'g' then (@UQty/$[POR1.U_BPQuantity.NUMBER])
    when $[POR1.U_UoM]  = 'kg' and $[POR1.U_BPUnit] = 'mg' then (@UQty/$[POR1.U_BPQuantity.NUMBER])
    when $[POR1.U_UoM]  = 'g' and $[POR1.U_BPUnit] = 'kg' then (@UQty/$[POR1.U_BPQuantity.NUMBER])
    when $[POR1.U_UoM]  = 'g' and $[POR1.U_BPUnit] = 'g' then 1
    when $[POR1.U_UoM]  = 'g' and $[POR1.U_BPUnit] = 'mg' then (@UQty/$[POR1.U_BPQuantity.NUMBER])
    when $[POR1.U_UoM]  = 'mg' and $[POR1.U_BPUnit] = 'g' then (@UQty/$[POR1.U_BPQuantity.NUMBER])
    when $[POR1.U_UoM]  = 'mg' and $[POR1.U_BPUnit] = 'kg' then (@UQty/$[POR1.U_BPQuantity.NUMBER])
    when $[POR1.U_UoM]  = 'mg' and $[POR1.U_BPUnit] = 'mg' then 1
    when $[POR1.U_UoM]  = 'kl' and $[POR1.U_BPUnit] = 'kl' then 1
    when $[POR1.U_UoM]  = 'kl' and $[POR1.U_BPUnit] = 'l' then (@UQty/$[POR1.U_BPQuantity.NUMBER])
    when $[POR1.U_UoM]  = 'kl' and $[POR1.U_BPUnit] = 'ml' then (@UQty/$[POR1.U_BPQuantity.NUMBER])
    when $[POR1.U_UoM]  = 'l' and $[POR1.U_BPUnit] = 'kl' then (@UQty/$[POR1.U_BPQuantity.NUMBER])
    when $[POR1.U_UoM]  = 'l' and $[POR1.U_BPUnit] = 'l' then 1
    when $[POR1.U_UoM]  = 'l' and $[POR1.U_BPUnit] = 'ml' then (@UQty/$[POR1.U_BPQuantity.NUMBER])
    when $[POR1.U_UoM]  = 'ml' and $[POR1.U_BPUnit] = 'l' then (@UQty/$[POR1.U_BPQuantity.NUMBER])
    when $[POR1.U_UoM]  = 'ml' and $[POR1.U_BPUnit] = 'kl' then (@UQty/$[POR1.U_BPQuantity.NUMBER])
    when $[POR1.U_UoM]  = 'ml' and $[POR1.U_BPUnit] = 'ml' then 1
    else 1
    end)
    Select @BPC
    I would like to know  where I am going wrong or if there is any simpler method for the above scenario?     
    Thanks and regards,
    Bharath S

    Try the third line change to:
    set @UQty = $[POR1.U_UnitQty.number]

  • Query using a Formatted Search

    Hi,
    I am trying to do the following but its not working and need a little help please.
    I have a series of UDF's on the Goods Receipt PO screen which I need populating on the batch transactions screen automatically.
    i.e I have a UDF called U_Width on the main Goods Receipt screen (PDN1) and when I click add on a batched item it asked me for the batch details.  I need the UDF in the Batch Screen (OIBT.U_Width) to be automatically populated with this information.
    I thought by using the following simple query and set as a formatted search would work but it doesn't seem to recognised the PDN1 table as a current document
    SELECT $[PDN1.U_Width]
    help please

    $ value will only work for current active form.  It is not possible to get the other form's value.
    Thanks,
    Gordon

Maybe you are looking for