How to show message in Movilizer data grid if no records found - movilizer

I am using data grid in movilizer screen with question type = "9". Here i am binding data to grid with local array data. I want to show message in the grid screen 'No records found' if there is no data. how to show message in the middle of the screen here.
below is my sample code
<question key="Item_Question" type="9" title="Item Details" tableOptionsEnabled="false" >
<answer nextQuestionKey="END" key="Item_1" clientKey="0" colIndex="0" colWidth="5" attributeType="8" dummyAnswer="true">
<text>Item ID </text>
</answer>
<answer nextQuestionKey="END" key="Item_2" clientKey="0" colIndex="1" colWidth="5" colSearchable="false"
attributeType="8" dummyAnswer="true" valueAlignment="CENTER">
<text>Item Description</text>
</answer>
<onEnterAssignment>
itemCount = $local:itemDetails;
for(clientKey : itemCount){
Seq = concat(itemCount[clientKey]['ID'], '_', itemCount[clientKey]['Name']);
addAnswer($answer:"Item_1", Seq, itemCount[clientKey]['ItemCode']);
setAnswerValueByClientKey($answer:"Item_1", Seq, itemCount[clientKey]['ItemCode']);
addAnswer($answer:"Item_2", Seq, itemCount[clientKey]['ItemDescription']);
setAnswerValueByClientKey($answer:"Item_2", Seq, itemCount[clientKey]['ItemDescription']);
}
</onEnterAssignment>
</question>
Thanks

You have lot of possibilities here.
First one is include a new entry in the dummy answer with that message, like this:
addAnswer($answer:"Item_1", "_Blank", "No records found");
setAnswerValueByClientKey($answer:"Item_1", "_Blank", "No records found");
addAnswer($answer:"Item_2", "_Blank", "");
setAnswerValueByClientKey($answer:"Item_2", "_Blank", "");
Another option is include a placeholder in question text element, and make it appear or dissapear if the local array has elements or not, just like this:
<text>%MY_MESSAGE%</text>
<onEnterAssignment>
itemCount = $local:itemDetails;
if (count($local:itemDetails) ?eq 0)
{
setPlaceholder("%MY_MESSAGE%", "No records found");
}
else
{
setPlaceholder("%MY_MESSAGE%", "");
}
</onEnterAssignment>
And, if you are developing with 2.6 version, maybe another option should be use the showDialog method. It will show a box like a warning message in your movilizer client. Here is an example:
showDialog(1, false, "Message title", "No records found", 14);

Related

When I make an e-mail intent in kotlin, the recipient mail is not added directly

binding.navView.setNavigationItemSelectedListener {
when(it.itemId){
R.id.requestWallpaper->{
val emailIntent=Intent().apply {
action=Intent.ACTION_SEND
data= Uri.parse("mailto:")
type="text/plain"
putExtra(Intent.EXTRA_EMAIL,"test#gmail.com")
putExtra(Intent.EXTRA_SUBJECT,"request wallpaper")
putExtra(Intent.EXTRA_TEXT,"request wallpaper")
}
if (emailIntent.resolveActivity(this!!.packageManager) !=null){
emailIntent.setPackage("com.google.android.gm")
startActivity(emailIntent)
}else{
Toast.makeText(this#MainActivity,"No app available to send email!!",Toast.LENGTH_SHORT).show()
}
}
When the navigation drawer opens, the user will want to make a wallpaper request and when he presses the imagebutton, I want him to send an e-mail to test#gmail.com via gmail for now, but test#gmail.com is not added directly to the "to" part of gmail.When I run it on the emulator, the email subject and e-mail text are added, but the recipient e-mail is not added, why?
You're so close here, the only thing that's missing is the Intent.EXTRA_EMAIL extra. That property is expecting an array of String values rather than a single String.
binding.navView.setNavigationItemSelectedListener {
when (it.itemId) {
R.id.requestWallpaper -> {
val emailIntent = Intent().apply {
action = Intent.ACTION_SEND
data = Uri.parse("mailto:")
type = "text/plain"
putExtra(Intent.EXTRA_EMAIL, arrayOf("test#gmail.com"))
putExtra(Intent.EXTRA_SUBJECT, "request wallpaper")
putExtra(Intent.EXTRA_TEXT, "request wallpaper")
}
if (emailIntent.resolveActivity(this.packageManager) != null) {
emailIntent.setPackage("com.google.android.gm")
startActivity(emailIntent)
} else {
Toast.makeText(
this#MainActivity,
"No app available to send email!!",
Toast.LENGTH_SHORT
).show()
}
}
}
}
I don't know that you need the type="text/plain" property either, but it shouldn't hurt anything. Also, if you skip the setPackage step it'll allow the OS to ask which email app to use.

React Native: Reach-Navigation and Pouch-DB - db.put not done before "refresh" callback is run

Relative newbie; forgive me if my etiquette and form here aren't great. I'm open to feedback.
I have used create-react-native-app to create an application using PouchDB (which I believe ultimately uses AsyncStorage) to store a list of "items" (basically).
Within a TabNavigator (main app) I have a StackNavigator ("List screen") for the relevant portion of the app. It looks to the DB and queries for the items and then I .map() over each returned record to generate custom ListView-like components dynamically. If there are no records, it alternately displays a prompt telling the user so. In either case, there is an "Add Item" TouchableOpacity that takes them to a screen where they an add a new item (for which they are taken to an "Add" screen).
When navigating back from the "Add" screen I'm using a pattern discussed quite a bit here on SO in which I've passed a "refresh" function as a navigation param. Once the user uses a button on the "Add" screen to "save" the changes, it then does a db.post() and adds them item, runs the "refresh" function on the "List screen" and then navigates back like so:
<TouchableOpacity
style={styles.myButton}
onPress={() => {
if (this.state.itemBrand == '') {
Alert.alert(
'Missing Information',
'Please be sure to select a Brand',
[
{text: 'OK', onPress: () =>
console.log('OK pressed on AddItemScreen')},
],
{ cancelable: false }
)
} else {
this.createItem();
this.props.navigation.state.params.onGoBack();
this.props.navigation.navigate('ItemsScreen');
}
}
}
>
And all of this works fine. The "refresh" function (passed as onGoBack param) works fine... for this screen. The database is called with the query, the new entry is found and the components for the item renders up like a charm.
Each of the rendered ListItem-like components on the "List screen" contains a react-native-slideout with an "Edit" option. An onPress for these will send the user to an "Item Details" screen, and the selected item's _id from PouchDB is passed as a prop to the "Item Details" screen where loadItem() runs in componentDidMount and does a db.get(id) in the database module. Additional details are shown from a list of "events" property for that _id (which are objects, in an array) which render out into another bunch of ListItem-like components.
The problem arises when either choose to "Add" an event to the list for the item... or Delete it (using another function via [another] slideout for these items. There is a similar backward navigation, called in the same form as above after either of the two functions is called from the "Add Event" screen, this being the "Add" example:
async createEvent() {
var eventData = {
eventName: this.state.eventName.trim(),
eventSponsor: this.state.eventSponsor.trim(),
eventDate: this.state.eventDate,
eventJudge: this.state.eventJudge.trim(),
eventStandings: this.state.eventStandings.trim(),
eventPointsEarned: parseInt(this.state.eventPointsEarned.trim()),
};
var key = this.key;
var rev = this.rev;
await db.createEvent(key, rev, eventData);
}
which calls my "db_ops" module function:
exports.createEvent = function (id, rev, eventData) {
console.log('You called db.createEvent()');
db.get(id)
.then(function(doc) {
var arrWork = doc.events; //assign array of events to working variable
console.log('arrWork is first assigned: ' + arrWork);
arrWork.push(eventData);
console.log('then, arrWork was pushed and became: ' + arrWork);
var arrEvents = arrWork.sort((a,b)=>{
var dateA = new Date(a.eventDate), dateB = new Date(b.eventDate);
return b.eventDate - a.eventDate;
})
doc.events = arrEvents;
return db.put(doc);
})
.then((response) => {
console.log("db.createEvent() response was:\n" +
JSON.stringify(response));
})
.catch(function(err){
console.log("Error in db.createEvent():\n" + err);
});
}
After which the "Add Event" screen's button fires the above in similar sequence to the first, just before navigating back:
this.createEvent();
this.props.navigation.state.params.onGoBack();
this.props.navigation.navigate('ItemsDetails');
The "refresh" function looks like so (also called in componentDidMount):
loadItem() {
console.log('Someone called loadItem() with this.itemID of ' + this.itemID);
var id = this.itemID;
let totalWon = 0;
db.loadItem(id)
.then((item) => {
console.log('[LOAD ITEM] got back data of:\n' + JSON.stringify(item));
this.setState({objItem: item, events: item.events});
if (this.state.events.length != 0) { this.setState({itemLoaded: true});
this.state.events.map(function(event) {
totalWon += parseInt(event.eventPointsEarned);
console.log('totalWon is ' + totalWon + ' with ' +
event.eventPointsEarned + ' having been added.');
});
};
this.setState({totalWon: totalWon});
})
.catch((err) => {
console.log('db.loadItem() error: ' + err);
this.setState({itemLoaded: false});
});
}
I'm at a loss for why the List Screen refreshes when I add an item... but not when I'm doing other async db operations with PouchDB in what I think is similar fashion to modify the object containing the "event" information and then heading back to the Item Details screen.
Am I screwing up with Promise chain someplace? Neglecting behavior of the StackNavigator when navigating deeper?
The only other difference being that I'm manipulating the array in the db function in the non-working case, whereas the others I'm merely creating/posting or deleting/removing the record, etc. before going back to update state on the prior screen.
Edit to add, as per comments, going back to "List screen" and the opening "Item Details" does pull the database data and correctly shows that the update was made.
Further checking I've done also revealed that the console.log in createEvent() to print the response to the db call isn't logging until after some of the other dynamic rendering methods are getting called on the "Item Details" screen. So it seems as though the prior screen is doing the get() that loadItem() calls before the Promise chain in createEvent() is resolving. Whether the larger issue is due to state management is still unclear -- though it would make sense in some respects -- to me as this could be happening regardless of whether I've called my onGoBack() function.
Edit/bump: I’ve tried to put async/await to use in various places in both the db_ops module on the db.get() and the component-side loadItem() which calls it. There’s something in the timing of these that just doesn’t jive and I am just totally stuck here. Aside from trying out redux (which I think is overkill in this particular case), any ideas?
There is nothing to do with PDB or navigation, it's about how you manage outer changes in your depending (already mounted in Navigator since they are in history - it's important to understand - so componentDidMount isn't enough) components. If you don't use global state redux-alike management (as I do) the only way to let know depending component that it should update is passing corresponding props and checking if they were changed.
Like so:
//root.js
refreshEvents = ()=> { //pass it to DeleteView via screenProps
this.setState({time2refreshEvents: +new Date()}) //pass time2refreshEvents to EventList via screenProps
}
//DeleteView.js
//delete button...
onPress={db.deleteThing(thingID).then(()=> this.props.screenProps.refreshEvents())}
//EventList.js
...
constructor(props) {
super(props);
this.state = {
events: [],
noEvents: false,
ready: false,
time2refreshEvents: this.props.screenProps.time2refreshEvents,
}
}
static getDerivedStateFromProps(nextProps, currentState) {
if (nextProps.screenProps.time2refreshEvents !== currentState.time2refreshEvents ) {
return {time2refreshEvents : nextProps.screenProps.time2refreshEvents }
} else {
return null
}
}
componentDidMount() {
this._getEvents()
}
componentDidUpdate(prevProps, prevState) {
if (this.state.time2refreshEvents !== prevState.time2refreshEvents) {
this._getEvents()
}
}
_getEvents = ()=> {
//do stuff querying db and updating your list with actual data
}

Creating alerts from changes at the item level in Netsuite

I am trying to incorporate a check at the item line level when creating an invoice. Basically if they are adding an item within a certain category (custitem8) i need an alert to pop up for the sales rep.
Not sure if this should be using fieldchanged or validateline.
Sorry Im not really a programmer and am learning on the job mostly by trial and error. Thanks for your help.
function ValidateLine(type)
{
if (nlapiGetCurrentLineItemValue('item', 'custitem8') = 'Order in Only - Not For Trade Guide')
{
alert("Order In Only, Please contact Purchasing");
}
return true;
}
The suggested code will not work, instead of using nlapiGetLineItemValue use nlapiGetCurrentLineItemValue.
the code should look like this.
postSourcing(sublistId, fieldId) {
if(sublistId == "item" && fieldId == "item") {
var itemId = nlapiGetCurrentLineItemValue(sublistId, fieldId);
var category = nlapiLookupField("item", itemId, "custitem8");
if(category == "Order in Only - Not For Trade Guide") {
alert("Order In Only, Please contact Purchasing");
}
}
}
I'm assuming you just need an alert when the user selects a line Item? If so, I would suggest using postSourcing(sublistId, fieldId) (though using validateLine(sublistId) works just fine).
As for the actual function content, I'm assuming (based on the field ID) "custitem8" is a field on the Item record. If so, you will have to load the field from the Item record first.
Based on my understanding of your post, I would go about it like this:
postSourcing(sublistId, fieldId) {
if(sublistId == "item" && fieldId == "item") {
var itemId = nlapiGetLineItemValue("item", "item");
var category = nlapiLookupField("item", itemId, "custitem8");
if(category == "Order in Only - Not For Trade Guide") {
alert("Order In Only, Please contact Purchasing");
}
}
}
And just a note, I don't really know the data type of the "custitem8" field, so I'm just assuming it's a free-form text field.

addEventListener in a chrome extension

I'm trying to make a simple domain check before sending an email on gmail. So I wrote the below code:
//debugger;
document.addEventListener('blur', function(event){
var target = event.target;
if (target.name !== 'to' && target.name !== 'cc' && target.name !== 'bcc') return;
console.log(target.name, ":", target.value);
},true); // event listener blur
I can see target.name on console window like "to:","cc:", or "bcc:". However, can not get value at all. Any advice appreciated. Thank you.
(What I believe to be)
The problem
Each time you add an address in recipient's field (to, cc, bcc), a new input field is appended to the element holding the recipient address (e.g. with name="to" and value=<email#addree.ss>). Furthermore, an empty textarea is always appended at the end and its purpose is to capture any new email address you might want to add (convert it to an input field as mentioned before and emptying itself again).
Use case:
You see 3 email addresses in the to field.
You click in the field (so it gains focus).
You click away (so it losses focus).
The following gets logged: to: (i.e. no value).
What actually happens, is that you log the value of the empty textarea at the end of the to field.
The solution:
Every time you catch a blur event related to a recipient's field, act upon (e.g. log) the values of all elements whose name equals the blurred field's name.
I know it doesn't make much sense, so here is an example:
document.addEventListener("blur", function(evt) {
var tname = evt.target.name;
if ((tname !== "to") && (tname !== "cc") && (tname !== "bcc")) {
return;
}
var elemList = document.querySelectorAll("[name='" + tname + "']");
[].slice.call(elemList).forEach(function(elem) {
console.log(elem.name, ":", elem.value);
});
}, true);

jquery-jable: How to display a field as read-only in the edit form?

I have a table pre-populated with the company LAN IP addresses with fields for associated data, status, etc. The (jquery-)jtable fields collection is configured like this.
fields: {
id: { title: 'ID'},
ip: { title: 'IP address, edit: false }
more: { ... }
}
This works but the problem is that when the edit dialog pops up the user can't see the ip address of the record being edited as jtable's edit form doesn't show the field.
I've read through the documentation but can't see any way to display a field as read-only in the edit form. Any ideas?
You don't need to hack the jTable library asset, this just leads to pains when you want to update to a later version. All you need to do is create a custom input via the jTable field option "input", see an example field setup to accomplish what you need here:
JobId: {
title: 'JobId',
create: true,
edit: true,
list: true,
input: function (data) {
if (data.value) {
return '<input type="text" readonly class="jtable-input-readonly" name="JobId" value="' + data.value + '"/>';
} else {
//nothing to worry about here for your situation, data.value is undefined so the else is for the create/add new record user interaction, create is false for your usage so this else is not needed but shown just so you know when it would be entered
}
},
width: '5%',
visibility: 'hidden'
},
And simple style class:
.jtable-input-readonly{
background-color:lightgray;
}
I have simple solution:
formCreated: function (event, data)
{
if(data.formType=='edit') {
$('#Edit-ip').prop('readonly', true);
$('#Edit-ip').addClass('jtable-input-readonly');
}
},
For dropdown make other options disabled except the current one:
$('#Edit-country option:not(:selected)').attr('disabled', true);
And simple style class:
.jtable-input-readonly{
background-color:lightgray;
}
I had to hack jtable.js. Start around line 2427. Changed lines are marked with '*'.
//Do not create element for non-editable fields
if (field.edit == false) {
//Label hack part 1: Unless 'hidden' we want to show fields even though they can't be edited. Disable the 'continue'.
* //continue;
}
//Hidden field
if (field.type == 'hidden') {
$editForm.append(self._createInputForHidden(fieldName, fieldValue));
continue;
}
//Create a container div for this input field and add to form
var $fieldContainer = $('<div class="jtable-input-field-container"></div>').appendTo($editForm);
//Create a label for input
$fieldContainer.append(self._createInputLabelForRecordField(fieldName));
//Label hack part 2: Create a label containing the field value.
* if (field.edit == false) {
* $fieldContainer.append(self._myCreateLabelWithText(fieldValue));
* continue; //Label hack: Unless 'hidden' we want to show fields even though they can't be edited.
* }
//Create input element with it's current value
After _createInputLabelForRecordField add in this function (around line 1430):
/* Hack part 3: Creates label containing non-editable field value.
*************************************************************************/
_myCreateLabelWithText: function (txt) {
return $('<div />')
.addClass('jtable-input-label')
.html(txt);
},
With the Metro theme both the field name and value will be grey colour.
Be careful with your update script that you're passing back to. No value will be passed back for the //edit: false// fields so don't include them in your update query.
A more simple version for dropdowns
$('#Edit-country').prop('disabled',true);
No need to disable all the options :)

Resources