Dismiss Notice
We would like to remind you that we’re updating our login process for all 3CX forums whereby you will be able to login with the same credentials you use for the Partner or Customer Portal. Click here to read more.

Change EXT Status Via api

Discussion in 'Call Flow Designer' started by Michael Groom, Dec 24, 2017.

Thread Status:
Not open for further replies.
  1. Michael Groom

    Joined:
    Dec 11, 2017
    Messages:
    63
    Likes Received:
    4
    I am trying to write a script that I can call via the cfd to change the status of an extension(available/away/or custom status). I have found a couple of examples but cant seem to get it to work. I have attached the script. Any help would be great.
     

    Attached Files:

    • pds2.png
      pds2.png
      File size:
      107.5 KB
      Views:
      30
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,611
    Likes Received:
    126
    Hello @Michael Groom,

    Can you try to get the Extension object as follows?
    Extension ext = PhoneSystem.Root.GetDNByNumber("001") as Extension;

    Kind regards.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Michael Groom

    Joined:
    Dec 11, 2017
    Messages:
    63
    Likes Received:
    4
    i tried using what you suggested but now get compiler errors when i try to build in cfd





    Compiling file Main.flow (C:\Users\bitty\Documents\pdsext\Main.flow)...
    Creating source code output...
    Compiling the created source code to .NET library...
    Error compiling source code to .NET library: (14,29): error CS1061: 'DN' does not contain a definition for 'CurrentProfile' and no extension method 'CurrentProfile' accepting a first argument of type 'DN' could be found (are you missing a using directive or an assembly reference?)
    Error compiling source code to .NET library: (14,50): error CS1061: 'DN' does not contain a definition for 'FwdProfiles' and no extension method 'FwdProfiles' accepting a first argument of type 'DN' could be found (are you missing a using directive or an assembly reference?)

    ----- Build process finished for project 'pdsext'.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Michael Groom

    Joined:
    Dec 11, 2017
    Messages:
    63
    Likes Received:
    4
    Here is my cs code
     

    Attached Files:

    • pds3.png
      pds3.png
      File size:
      106.8 KB
      Views:
      21
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,611
    Likes Received:
    126
    This is weird, because the compiler error mentions that the object DN doesn't have some methods. And then the problem would be the missing cast from DN to Extension. But the screenshot shows that you have the cast, so it seems that the error is from a different piece of code... Please try the code exactly as I gave it to you and let me know if that works...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Michael Groom

    Joined:
    Dec 11, 2017
    Messages:
    63
    Likes Received:
    4
    I found the isse. It was CFD. i deleted the project and recreated it with the above code and it built right away and functions properly. One other thing i have noticed. I have changed my code to update all extensions in the system but found a weird behavior. Because of using the FwdProfile array, some extensions are not changing to the correct status. Is there a way to set it implicitly using a string with the name of the status?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    #6 Michael Groom, Dec 29, 2017
    Last edited: Dec 29, 2017
  7. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,611
    Likes Received:
    126
    Thanks for the feedback, glad to hear that it's working.

    In order to do the same for every extension in the system, you need to iterate the array returned by PhoneSystem.Root.GetExtensions().

    Kind regards.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. Michael Groom

    Joined:
    Dec 11, 2017
    Messages:
    63
    Likes Received:
    4
    I am able to call all extensions at once as stated above. When i do call all extensions and use
    {
    ext.CurrentProfile = ext.FwdProfiles[1];
    ext.save;
    }

    I get unexpected results. All of the extensions change but not all of them change to the correct profile, some of them will change to a different profile that what is expected. So is there a way to change the profile using a name string, rather than using the FwdProfiles[] array.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,611
    Likes Received:
    126
    Profiles can be at different positions of the array for different extensions. You need to check the name in order to select the right one.

    The class "FwdProfile" has the property "Name" which will tell you which profile it is.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. Michael Groom

    Joined:
    Dec 11, 2017
    Messages:
    63
    Likes Received:
    4
    OK i will try and figure this out
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. Michael Groom

    Joined:
    Dec 11, 2017
    Messages:
    63
    Likes Received:
    4
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,611
    Likes Received:
    126
    Can you post the error message you get and the script you're using??
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Thread Status:
Not open for further replies.