Community discussions

MikroTik App
 
User avatar
akira463
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 50
Joined: Thu Jan 11, 2018 12:30 pm
Location: Ph

How to fix my code? comments turns to be equal to each other?

Sun Jan 29, 2023 7:39 am

How to fix my code? comments turns to be equal to each other? what could be the problem?

heres my code
{
/ppp secret
:foreach item in=[find] do={
	:local prof [get $item profile]
	:local comm [get $item comment]
	:local profCom "10 MBPS old 599 test"

	:if (($prof) = ($profCom)) do={
	:local accNum [:pick $comm ([:find $comm "Number: "] + 8) [:find $comm " Plan:"]]
	:local cost [:pick $comm ([:find $comm "Cost: "] + 6) ([:len $comm])]
	:local bill ($cost + 899)
	:local billmsg "Acc Number: $accNum Plan: 10mbps Cost: $bill"
	
	[/ppp secret set [find profile="10 MBPS old 599 test"] comment=$billmsg]
	:delay 1
	} else={
	:log warning "hays"
	}
	}
}


on this image acct number and bill are different .
p1.png




then when i run the code, they became same value
p2.png




Please help, thankyou
You do not have the required permissions to view the files attached to this post.
 
User avatar
akira463
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 50
Joined: Thu Jan 11, 2018 12:30 pm
Location: Ph

Re: How to fix my code? comments turns to be equal to each other?

Sun Jan 29, 2023 2:55 pm

is there anyone ? please help .
 
tomislav91
Member
Member
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: How to fix my code? comments turns to be equal to each other?

Sun Jan 29, 2023 3:58 pm

is there anyone ? please help .
It seems that the issue is that the $billmsg variable is being overwritten in each iteration of the loop, resulting in all PPP secrets having the same comment. To fix this, you can modify the $billmsg variable by including the value of $item to create a unique value for each PPP secret:
:local billmsg "Acc Number: $accNum Plan: 10mbps Cost: $bill ($item)"
This way, the comment for each PPP secret will be unique and not equal to each other.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: How to fix my code? comments turns to be equal to each other?

Sun Jan 29, 2023 6:04 pm

@tomislav91
It's time you try to understand what is being asked before answering...

@akira463
When you have two different comments like this
"Acc Number: 2021022 Plan: 35mbps Cost: 599"
"Acc Number: 2021021 Plan: 35mbps Cost: 4507"
You must search the original comment, for example "Acc Number: 2021022 Plan: 35mbps Cost: 599", for replace it with new comment with updated cost,
not generically the profile that have the user "10 MBPS old 599 test",
but you already have the item index $item inside the cycle, you not need to search again, just set the value on index,
and with putting the profile in the [find] you do not need to check it again inside if is present the comment or not.

I can not test the script because I do not have such profile and users, but must be like this:

revised code

/ppp secret
{
:local profCom "10 MBPS old 599 test"
 :foreach item in=[find where profile=$profCom] do={
	:local comm   [get $item comment]
	:local accNum [:pick $comm ([:find $comm "Number: "] + 8 ) [:find $comm " Plan:"]]
	:local cost   [:tonum [:pick $comm ([:find $comm "Cost: "] + 6) ([:len $comm])] ]
	:local bill   ($cost + 899)
	:local billmsg "Acc Number: $accNum Plan: 10mbps Cost: $bill"
	set $item comment=$billmsg
	:delay 1s
 }
}
 
User avatar
akira463
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 50
Joined: Thu Jan 11, 2018 12:30 pm
Location: Ph

Re: How to fix my code? comments turns to be equal to each other?

Mon Jan 30, 2023 12:54 am

Thankyou again , sir rextended , youre such a life saver!!. thankyou so much , i hope that youll never get tired of helping me :-D :-D :-D . Godbless!
 
copygigantic
just joined
Posts: 1
Joined: Tue Aug 22, 2023 9:45 am

Re: How to fix my code? comments turns to be equal to each other?

Tue Aug 22, 2023 9:48 am

It seems that the issue is that the $billmsg variable is being overwritten in each iteration of the loop, resulting in all PPP secrets having the same comment. To fix this, you can modify the $billmsg variable by including the value of $item to create a unique value for each PPP secretmini crossword:
:local billmsg "Acc Number: $accNum Plan: 10mbps Cost: $bill ($item)"
This way, the comment for each PPP secret will be unique and not equal to each other.
Find the original comment by searching for a phrase like "Acc Number: 2021022" Plan: 35mbps Cost: 599", to update the profile with a new note reflecting the new price, rather than the generic "10 MBPS old 599 test".
Last edited by copygigantic on Tue Aug 22, 2023 9:49 am, edited 1 time in total.

Who is online

Users browsing this forum: sstefanov and 25 guests