51) How to concatenate the URL and open in new URL in new tab of browser

. Hello every one during the time of working i got one requirement to concatenate the URL and pass the parameter in It and open in the new tab of browser

Business requirement : - 

1.     New parameter field ‘DPMS URL’ will be added in ‘Asset Management parameters’ form to define the URL template for each legal entity.

      2. New field ‘Work Order Type Classification’ field will be added in ‘Work Order Type’ form to identify the DPMS work order type or pipeline work orders.

3   3. New button ‘DPMS Link’ will be added in Work order action pane to provide the link to the DPMS.

SStep 1: - Firstly create a unified class  to concatenate the URL: - 

// <summary>
/// The <c>AVAUrlFormat</c> class handles the replace of string
/// </summary>
class AVAUrlFormat
{
    /// <summary>
    /// concatenate the String based on the map
    /// </summary>
     public static str formatUrlFromMap(str _templateString, Map _variableMap)
    {
        MapEnumerator mapEnumerator = _variableMap.getEnumerator();
        str           resultString  = _templateString;

        while (mapEnumerator.moveNext())
        {
            //Here it will replace the string 
            resultString = strReplace(resultString, mapEnumerator.currentKey(), mapEnumerator.currentValue());
        }

        return resultString;
    }

  Step 2 : - Create the another class and call this method to open in the new browser 


// /// <summary>
/// The <c>AVADpmsOpenUrl</c> class handles the Validation and replace the string
/// </summary>
class AvaEntAssetDpmsOpenUrl
{
    AvaPipelineKMPost         kmPostValue;
    AvaPipelineYearOfIssue    yearOfIsssue;
    str                       sourceID;

    const str   kmPost = '{KmPost}';
    const str   year   = '{YearOfIssue}';

    /// <summary>
    /// Method will helps to open the DPMS Url to a new tab in browser
    /// </summary>
    public static void main(Args _args)
    {
        AvaEntAssetDpmsOpenUrl          openDpmsUrl;

        switch(_args.dataset())
        {
            case tableNum(EntAssetWorkOrderTable):
                openDpmsUrl = AvaEntAssetDpmsOpenUrl::ConstructFromWorkOrderTable(_args.record() as EntAssetWorkOrderTable);
                break;
            default:
                throw error(strFmt("@AVATransMountain:AVAParameterIsMissingValue_Label", tablePName(EntAssetWorkOrderTable)));

        }

        if (openDpmsUrl.validate())
        {
            openDpmsUrl.run();
        }
       
    }

    protected void new()
    {
    }

    public static AvaEntAssetDpmsOpenUrl ConstructFromWorkOrderTable(EntAssetWorkOrderTable _workOrderTable)
    {
        var openDpmsUrl = new AvaEntAssetDpmsOpenUrl();
        openDpmsUrl.parmKMPost(_workOrderTable.AvaPipelineKMPost);
        openDpmsUrl.parmYearOfIssue(_workOrderTable.AvaPipelineYearofIssue);
        openDpmsUrl.ParmSourceID(_workOrderTable.WorkOrderId);
        return openDpmsUrl;
    }

    public boolean validate()
    {
        boolean                 ret = true;
     
        if (!kmPostValue )
        {
            ret = checkFailed(strFmt("@AVATransMountain:AVADPMSMissingField_Label", sourceId, fieldId2Name(tableNum(EntAssetWorkOrderTable),fieldnum(EntAssetWorkOrderTable, AvaPipelineKMPost))));
        }

        if (!yearOfIsssue)
        {
            ret = checkFailed(strFmt("@AVATransMountain:AVADPMSMissingField_Label", sourceId, fieldId2Name(tableNum(EntAssetWorkOrderTable),fieldnum(EntAssetWorkOrderTable, AvaPipelineYearofIssue))));
        }

        return ret;
    }

    public AvaPipelineKMPost parmKMPost(AvaPipelineKMPost _kmPostValue)
    {
        kmPostValue = _kmPostValue;
        return kmPostValue;
    }

    public AvaPipeLineYearOfIssue parmYearOfIssue(AvaPipeLineYearOfIssue _yearOfIsssue)
    {
        yearOfIsssue = _yearOfIsssue;
        return yearOfIsssue;
    }

    public str ParmSourceID(str _sourceID)
    {
        sourceID = _sourceID;
        return sourceID;
    }

    /// <summary>
    /// runs the actual logic
    /// </summary>
    public void run()
    {
        str     url;
        str     dpmsUrl;

        url     = AvaEntAssetGlobalParameters::find().PipelineUrlTemplate;
        dpmsUrl = this.formatUrl(url, kmPostValue, yearOfIsssue);

        //To open the Url in  browser  new Tab
        Browser browser = new Browser();
        browser.navigate(dpmsUrl, true, false);
    }

    private str formatUrl(AvaPipelineUrlTemplate _url, AvaPipelineKMPost _kmPost, AvaPipeLineYearOfISsue _year)
    {
        Map urlMap = new Map(Types::string, Types::String);
       
        urlMap.insert(kmPost, Global::real2double(_kmPost).ToString());
        urlMap.insert(year, int2Str(_year));

        // Here we have to pass the parameter which calls the another method to get the final URL Value.
        return AVAUrlFormat::formatUrlFromMap(_url, urlMap);
    }

}

IIn this way we can cocatenate the url and gets the value of it  the url we are using like this 
    

    We have the URL like this to be put in the parameter for 

    Link Details : - Link http://xxxxxxx/xxxxx/xxxxxxx?kp={KmPost}&year={YearOfIssue}  

C   Converted In to the below Link : - 


}
}







Comments

Post a Comment

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++