Forum Discussion

atulchaudhari32's avatar
atulchaudhari32
New Contributor
1 month ago

capture variable from the popup in Desktop application

How to capture client id and client name from this desktop application using Javascript. The client id and name is changing every time whenever we create the new client

2 Replies

  • MW_Didata's avatar
    MW_Didata
    Super Contributor

    You're can save the text into a variable and then start extracting the info

    If the Customer number is always in the same place then remove the "Client " part of the string.

    Then if its always the same length remove everyting after the length of the customer number.
    if the length is not always the same look for the position of the first " " (space) in the remaning string and remove everyting after that including the space itself

    The customerName might be more tricky since it might or might not contain a space.

    I would suggest finding the position of the " has been...." and calculate from there what part of the string you need.



    To manipulate a string you can use the aqString methods:

    https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/methods.html 

    I had a similar issue where I would need to extract an ordernumber from a msgbox string,

    Since most of the string didnt change only the number I just went step by step removing the unneeded parts of the string until only the ordernumber was left.

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    Using Regular Expression, you can do something like this

    function test1()
    {
        var messageBox = "Client 121157871 Atul Patil Sancheti has been successfully added.";
    
        // RegEx
        var regex = /Client\s+(\d+)\s+(.+?)\s+has been successfully added\./;
        var match = regex.exec(messageBox);
    
        if (match != null) {
            var clientId = match[1];    // 121157871
            var name = match[2];        // Atul Patil Sancheti
    
            Log.Message("Client ID: " + clientId);
            Log.Message("Name: " + name);
        }
    }