Solved C# code to check Extension

Status
Not open for further replies.

FG Admin

Customer
Joined
Jun 21, 2021
Messages
18
Reaction score
5
I was looking for ways to check if the user's input is a valid extension or not (if the extension exists or not) and if the extension was registered or not (is it logged in on any soft/desktop phone or Mobile App).
I found some code here on the forums to do that, But since I am not a developer myself, I was struggling trying to use this code.
For example, this method:
C#:
PhoneSystem.Root.GetDNByNumber()
I tried using it this way
C#:
public bool CheckValidExt(string UserInput)
{
    DN dn = PhoneSystem.Root.GetDNByNumber(UserInput);
    
    return (dn != null);
}
1711546757529.png
But received the following error
C#:
2024/03/27 15:59:27.643|12660|0006|Err|ScriptRunner.ScriptRunner-----
:[31013..31026)E: (610,27)-(610,40): Error CS0161: 'Main.CheckValidExtC682329230ECCComponent.CheckValidExt(string)': not all code paths return a value
            private object CheckValidExt(string UserInput)
                           ^^^^^^^^^^^^^
:[31077..31083)E: (612,12)-(612,18): Error CS0106: The modifier 'public' is not valid for this item
            public bool CheckValidExt(string UserInput)
            ^^^^^^
:[31089..31102)W: (612,24)-(612,37): Warning CS8321: The local function 'CheckValidExt' is declared but never used
            public bool CheckValidExt(string UserInput)
                        ^^^^^^^^^^^^^
-------FAILED to compile---------
I was looking for pointers on how I would use this method (including Execute C# code component config ie: Method Name, Input parameters)
As well as this code to check the entered extension registration status:
C#:
return ((Extension)PhoneSystem.Root.GetDNByNumber(extensionNumber)).IsRegistered;

Thanks in advance.
 
Remove the method signature, leave only the method body in the Execute C# Code. It already wraps it in a method.
 
Thanks, it seems to be compiling alright now. I will make some audio prompts and a condition to parse the return value, whether true or false (easier to debug that way instead of reading the log:D).
 
Last edited:
Thank you so much, both methods worked exactly as needed.
You can mark this thread as solved.
Another thing: very special thanks to both @ConceptsWeb and @edossantos You have helped me way more than you know, I have been reading your answers to other forum users' questions for two weeks now (ranging from 2017 to 2023 !) and I managed to create my current call flow (way more complex to my liking and in a sense replicates the already built in IVR functionality @ConceptsWeb I read that reply by the way and felt personally attacked xD but to be fair to myself I haven't come up with a better way around the V18 Queues working hours limitations nor have I found this thread when I first set on to make my call flow) but now that it's done I might as well use it :). Anyway, I just wanted to say that this has been possible only thanks to you two ♥♥♥.
 
Thank you so much, both methods worked exactly as needed.
You can mark this thread as solved.
Another thing: very special thanks to both @ConceptsWeb and @edossantos You have helped me way more than you know, I have been reading your answers to other forum users' questions for two weeks now (ranging from 2017 to 2023 !) and I managed to create my current call flow (way more complex to my liking and in a sense replicates the already built in IVR functionality @ConceptsWeb I read that reply by the way and felt personally attacked xD but to be fair to myself I haven't come up with a better way around the V18 Queues working hours limitations nor have I found this thread when I first set on to make my call flow) but now that it's done I might as well use it :). Anyway, I just wanted to say that this has been possible only thanks to you two ♥♥♥.
V20 will probably fix a lot of things for you. Call queues can follow department hours and have different behaviors based on that.
 
Status
Not open for further replies.

Forum statistics

Threads
111,974
Messages
590,081
Members
164,899
Latest member
mazet