osclass current user id function returns 0 as result in plugin custom page - helper

I want to list the current user items in my custom page and add some custom operations in that custom page, But i can't get current user id from hUsers helper using this function:
osc_user_id();
it returns 0 as the result.
what can i do to achieve this?
thanks in advance.

If you're on a custom plugin page, you have to export the user manually.
How to export the user on custom page in Osclass
View::newInstance()->_exportVariableToView("user", User::newInstance()->findByPrimaryKey($userId));
If you're in a controller,
$this->_exportVariableToView("user", User::newInstance()->findByPrimaryKey($userId));
Then, $userId will depend on which user you refer to:
You can get it from the URL: use Params::getParam('userId') and passing it as a GET parameter.
/index.php?page=custom&route=your_plugin_route&userId=12
Use the current logged user id: osc_logged_user_id()
See also
This tutorial on how to develop Osclass plugins, might be useful.

Related

set calculated property on model only once

im using python3 + django, and i have
a model of User with few fields
an admin page where all the users are presented
a form page where a single user is presented and can be updated
an external API with 2 endpoints:
GET /api/users/name (get all names for all the users)
GET /api/users/:id/name (get name for user by id)
i want to add a name property to be presented on admin page (as a column) and on a form page (read-only, not changeable)
how can i add this "calculated" property without calling an api more than needed?
it is normal function, you should create new method in ModelAdminand you can use result of this method in render.
more here:
https://docs.djangoproject.com/en/4.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.readonly_fields
if you want to get username as readonly in list and in form, add this method in list_display and in field or fieldsets Modeladmin options.
You don't need to use other api, if you has already users list.

How to get current user's custom information and show it on any screen?

I had made a custom field 'warehouse' on User screen(SM201010), and saved some text in this field to the user 'user1'.
The question is when I login as the user1. How can I display the 'warehouse' field on any screen else?
I had try AccessInfo, but dont know how it works. Please help! Thx!
AccessInfo contains basic information on the current user, but adding a custom field to the User screen will not add it as a member of AccessInfo.
If you added a custom field in a DAC Extension, you will need to fetch the User record, get its extension and then you can access this custom value.
Here are some links about extensions :
https://docref.acumatica.com/(W(1))/Wiki/ShowWiki.aspx?pageid=3a427466-1925-4799-8fee-fe34a77021d0
https://docref.acumatica.com/Main.aspx?ScreenId=ShowWiki&pageid=114ae5af-8667-4933-b53d-c4c8667c85ac
I highly suggest you complete the T300 certification class which teaches how to do customizations in Acumatica. It is available in our Open University

Use Module setting in Products

I have created a module called login_to_see_price. This module is used to hide the price of product if user is not not logged in. The module is working fine in admin part. But i am not getting any idea of implementing the settings of the module in all product.
Module have form fields
status which can be 0=>disable 1=>enable
language (the sentence that is used instead of price) => Login to see price
I have kept these value in setting table.
So, when admin enable the setting i.e. status=1
then in froentend in place of product price i needed to display language=Login to see price .
How can i implement this ?
You can do this in each controller where you want to implement this feature. You can do like
if($this->config->get('your_module_status')){
login to see price and other code
}else{
default functionality
}
Opencart Default provide this feature.
Edit setting / option tab under the Account Title there is Option Login Display Price.

netsuite customer center saved search

I have created a saved search for a custom record with available filters. I have then added a Customer Center category called Information and in this category added a Link to the search form. I have added the necessary permissions to the customer center role to view the record and the search form. However, the search form does not appear in the customer center.
For it to appear I need to set permission on the custom record to No Permissions. The result is that when the search is run in the customer center, the user can view and edit the search result lines and hence the custom record...
Is there any way to avoid this: allow user to view search results but not view and edit the records? I have seen I can publish a saved search, however I would rather have a search form that allows the user to use the available filters.
If you simply want to avoid access to the custom record you can use a WorkFlow or a UserEvent script to blowup the request, with a nice message of course ;)
If I had this requirement I would probably do something like this:
Redirect to a page (SuiteLet) with clietn script deployed to pop-up a message "Access denied, fool!"
Once the user confirmed (i.e. clicked 'OK') I would redirect back to the search results
You'd lose any filters and scrolling settings but that's not a big price to pay. Even then you can get into parsing the nlobjRequest and look for the filters as params that you can pass down the redirect chain and then use nlapiRequestURL with the params to restore your filters. I don't know if that last part is actually possible but it's a concept.
Thanks for your response and solutions.
In my particular case, I'm adding a link to a custom record search.
I found that by restricting the permissions to the custom record to Edit only, than the user is not able to drill down to view or edit the custom record.
I did this as follows:
Setup > Users/Roles > Edit my customer center role > Permissions (sub tab) > Custom Record (sublist) > my custom record > Restrict > set to Edit Only.

Groovy session. How to find the user name

I am developing an application under Groovy using scafoldig.
We are using the Acegi plugin for security.
We have a class called ChangeManagement defined as follows (simplified version)
class ChangeManagement {
static constraints = {
company(nullable:false)
lastModifiedByUser(nullable:false)
}
Company company
static belongsToCompany = [company:Company]
User lastModifiedByUser
static belongsToUser = [lastModifiedByUser:User]
}
When I address the create method I will get a pull-down menu
with the label "Last Modified By" with all the users from the table Users,
which is the standard behaviour.
Instead of this I would like to have directly the user who is already logged in and
no pull down menu. I've already generate the create template and I can modify it.
I am assuming that I have to get the username from the session.
If my assumption is true, how to get this username? and if I am wrong then from where can I get the username of the current user?
Thanks in advance.
See this question for details on how to get the current username.
I'd also suggest looking into Grails Filters for one way to easily stuff the user into the model after all controller calls and make it available in the view. I use this on my app to put the name of the logged in user in the upper right hand corner of the screen.

Resources