Saturday 3 August 2019

BQL Snippet Helper


BQL Snippet Helper

 Overview:
This Document is aimed at creating custom code snippets For BQL in Visual Studio.
 
 WRITING A CUSTOM SNIPPET:

          
I’m going to show you a snippet that generates an outline for a Simple BQL View. It is a little simplistic, but shows you how to make parts of the snippet user-editable.

    Below code snippet file generates simple BQL View.



 Steps to create Code snippet File:

  • Add new XML file and change extension from XML to .snippet .


We divide the whole XML into three parts :

1. The header section :





è               <Title>: Specifies the Title for the Code snippet.

è              <ShortCut>: Specifies the shortcut text used to insert the snippet.

è            <description>: Specifies Descriptive information about the contents of an                            Intellisense code snippet.

è          <SnippetTypes>: Groups individual snippet type elements. If the snippet type element is not present, the code snippet can be inserted anywhere in the code.
  • <SnippetType>Expansion</SnippetType> :
A value of expansion allows the code snippet to be inserted at the cursor.
  • <SnippetType>SurroundsWith</SnippetType> :
     A value of sorroundswith allows the code snippet to be placed around a selected peace of code.
  •   Above fields can display like below screenshots




2. Declarations(variables) Section:
    In Declarations section, we define variables for which we want to input during the use of it. we can declare literals or objects that need to be replaced within snippet and the same can be referred in the snippet using $name$

3. Snippet Code Declaration:

                         In this section we will declare our code snippet by using defined variables in declaration section. The code is written inside the Code element and we put parameters wrapped within $ sign and these will be replaced when we use it in code.



  • ID: Required element. Specifies a unique identifier for a Literal or Object element. No two literals or objects in the same code snippet can have the same text value in their ID elements. Literals and objects cannot contain an ID element with a value of end. The value $end$ is reserved.

  • ToolTip: Optional element, Describes the expected value and usage of a literal or object in a code snippet, which Visual Studio displays in a ToolTip when it inserts the code snippet into a project. The ToolTip text is displayed when the mouse hovers over the literal or object after the code snippet has been inserted.

  • Default: Specifies the default value of the literal or object for an IntelliSense Code Snippet.
  • Code: This element is used to define the code to be inserted, represented by a CDATA(CDATA sections are used to defined data that is not well-formed XML, but still required by the XML document)section.

Simple BQL View Code: 
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">

  <CodeSnippet Format="1.0.0">

    <Header>

      <Title>BQL Select View</Title>

      <Shortcut>KNBSelView</Shortcut>

      <Description>Code snippet for BQL Select Query</Description>

      <Author>vishnu mechineni</Author>

      <SnippetTypes>

        <SnippetType>Expansion</SnippetType>

      </SnippetTypes>

    </Header>
   
    <Snippet>
      <Declarations>

        <Literal>

          <ID>TblName</ID>

          <ToolTip>Table Name</ToolTip>

          <Default>DACName</Default>

        </Literal>

        <Literal>

          <ID>colName</ID>

          <ToolTip>Column Name</ToolTip>

          <Default>FiledName</Default>

        </Literal>

        <Literal>

          <ID>ViewName</ID>

          <ToolTip>View Name</ToolTip>

          <Default>ViewName</Default>

        </Literal>


      </Declarations>


      <Code Language="csharp">

        <![CDATA[

           

       /// BQL for $ViewName$     
      
       public PXSelect<$TblName$, Where<$TblName$.$colName$, Equal<Current<$TblName$.$colName$>>>> $ViewName$;
                 

   $end$]]>

      </Code>

    </Snippet>

  </CodeSnippet>

</CodeSnippets>



-------------------------------------------------------------------------------------------------------

BQL Select join view with 3 tables:


<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">

  <CodeSnippet Format="1.0.0">

    <Header>

      <Title>BQL Select Join view</Title>

      <Shortcut>KNBSelJoinView3</Shortcut>

      <Description>Code snippet for BQL Select join view with 3 tables</Description>

      <Author>vishnu mechineni</Author>

      <SnippetTypes>

        <SnippetType>Expansion</SnippetType>

      </SnippetTypes>

    </Header>

    <Snippet>
      <Declarations>

        <Literal>

          <ID>TblName1</ID>

          <ToolTip>Table Name1</ToolTip>

          <Default>DACName1</Default>

        </Literal>

        <Literal>

          <ID>TblName2</ID>

          <ToolTip>Table Name2</ToolTip>

          <Default>DACName2</Default>

        </Literal>

        <Literal>

          <ID>TblName3</ID>

          <ToolTip>Table Name3</ToolTip>

          <Default>DACName3</Default>

        </Literal>

        <Literal>

          <ID>colName1</ID>

          <ToolTip>Column Name</ToolTip>

          <Default>colName1</Default>

        </Literal>

        <Literal>

          <ID>colName2</ID>

          <ToolTip>Column Name</ToolTip>

          <Default>colName2</Default>

        </Literal>

        <Literal>

          <ID>colName3</ID>

          <ToolTip>Column Name</ToolTip>

          <Default>colName3</Default>

        </Literal>

        <Literal>

          <ID>ViewName</ID>

          <ToolTip>View Name</ToolTip>

          <Default>ViewName</Default>

        </Literal>


      </Declarations>


      <Code Language="csharp">

        <![CDATA[                  

       /// BQL for select Join $ViewName$   
      
          public PXSelectJoin<$TblName1$,
            InnerJoin<$TblName2$,On<$TblName2$.$colName1$, Equal<$TblName1$.$colName1$>>,
            LeftJoin<$TblName3$, On<$TblName3$.$colName2$,Equal<$TblName2$.$colName2$>,
           And<$TblName3$.$colName3$,Equal<$TblName2$.$colName3$>>>>>> $ViewName$;       
   $end$]]>

      </Code>

    </Snippet>

  </CodeSnippet>

</CodeSnippets>
-------------------------------------------------------------------------------------------------------


No comments:

Post a Comment

What is Acumatica?

Acumatia ERP     Acumatica is a cloud ERP system designed for the SMB market. Acumatica includes functionality for financial management, ...