Javascript text field will not fire - javascript

I am trying to programmatically input text in a textfield of an AJAX website which then updates a list of stores. Unfortunately, the list of stores only updates when the browser window is showing. Whenever the browser window is hidden, my code always generates the default list and not the updated list.
Here is my code (I am using Python / Selenium):
def select_state(driver, state):
# select a state
log = logging.getLogger(__name__)
log.debug("Select a state")
xpath = '//*[#id="store-finder"]'
driver.implicitly_wait(10)
wait = WebDriverWait(driver, 5)
wait.until(ec.presence_of_element_located((By.XPATH, xpath)))
element = driver.find_element(By.XPATH, xpath)
element.clear()
logger.info("Processing state {0}".format(state))
element.send_keys(state + Keys.TAB)
The problem occurs when it reaches "element.send_keys(state + Keys.TAB)". The state is keyed in properly into the text field but the list of stores does not update. I have tried (i) Keys.RETURN, (ii) executing JavaScript directly (i.e. river.execute_script()), (iii) including implicit_wait() times, (iv) even explored how to deconstruct the encrypted XHR request which generates the store list.
Any suggestions would be greatly appreciated.
Thank you

Related

How to define where function is slows down?

I have report view where a bunch of controls located, there is an example code:
#Html.DevExpress().DropDownEdit(
settings =>{
settings.Name = "SomeList";
settings.Width = 100;
settings.SetDropDownWindowTemplateContent(c =>{
#Html.DevExpress().ListBox(
...
).BindList(ViewData["SomeList"]).Render();
some code...
).GetHtml()
When it render first time it works fine, but in business logic there is another drop down let's call it dropdown #2. When user select some values in dropdown#2 JS handle this action send request to the server to get actual value for first dropdown, then clear all rendered values from dropdown #1 and insert new items.
And problem in performance lies in how devexpress create new items on client side. From backend there is now 8000 new items can be added to dropdown #1 and it keep growing. And user must wait 5-10 seconds when browser render it. I tried to research what is happening when new item is creating but there are a lot of devexpress function which call another functions.
JS code look's like:
SomeList.BeginUpdate();
l = data.SomeList.length;
while (x < l) {
SomeList.AddItem(data.SomeList[x].Name, data.SomeList[x].Id);
x++;
}
SomeList.EndUpdate();
BeginUpdate and EndUpdate is devexpress functions that prohibbit browser render control while adding new items. Without this function it takes eternity to finish adding new items.
I know start point of problem it is - item creating code SomeList.AddItem(...).
So my question: is there way to do something like console.trace(SomeList.AddItem(...)) and see full trace which will be executed on first code pass?
Also is there way to determine which function call take alot of time to execute?

Why does my document render event listener works with all edit entries except for a newly added entry without a page refresh?

I have a document render event listener to catch changes to my list. If I edit the time value of an entry, it will auto update other fields for that entry (such as milliseconds). This works for all records EXCEPT in the case when I add a new record, then go to edit that record. The edit screen freezes upon submit and the console tells me "cannot read field value of undefined". Instead of undefined it should be the time value. Why is my field value undefined?
I've tried removing the if conditional (this results in no auto updates at all).
$(document).on('knack-records-render.view_2320', function(event, scene, records) {
$(document).on('knack-record-update.view_2321', function(event, view, updatedRecord) {
// Filter the initially loaded records for the one with the same ID as the updated one
var recordBeforeUpdate = records.filter(recordFromRenderEvent => {
return recordFromRenderEvent.id === updatedRecord.id;
})[0];
if (updatedRecord.field_1876 !== recordBeforeUpdate.field_1876) {
var recordId = updatedRecord.id
//then i calculate milliseconds and use ajax call to send data
When I add new entry (using $(document).on('knack-record-create.view_2323') then edit this entry it says field_1876 is undefined and does not do the auto update! updatedRecord.field_1876 should be newly put time value and recordBeforeUpdate.field_1876 should be time value before edit. Neither should be undefined. If I refresh page after adding entry then it works. I want it to work without a page refresh.

Odoo10/Odoo11 dynamic progressbar - trigger javascript function inside python

My task: a dynamic progress bar in odoo.
I'm using the Odoo widget: 'progressbar'. I want to update the view every time the value is updated - hence I want to trigger the on_change_input javascript function inside my python write method to render the view.
#api.one
def updatevalue(self, val):
self.value = val
# TODO call javascript function on_change_input()
The purpose is, that the progressbar should be updated while a process is running and the user should see the progress without updating the site.
Is my task possible with the progressbar widget? Or is there another possibility to show dynamic content in Odoo?
If I use my updatevalue method as button, the progressbar is updated after clicking the button without calling the javascript function & without refreshing the page... but I do want to call the method in my code (and probably over rpc) therefore this does not help -.-
Thank you for your time!
Here is the workflow I have so far:
The user clicks on the button do_time_consuming_task
and the following function is called:
def do_timeconsuming_task(self):
ws = websocket.WebSocket()
ws.connect('ws:/129.0.0.1:1234/')
data = { 'topic' : 'server_command', 'id' : self.id, 'commandName' : 'do_sth',}
payload = ujson.dumps(data)
ws.send(payload)
ws.close()
On the server, the command is received and processed. There is an open rpc connection:
odoo = odoorpc.ODOO("129.0.0.1", port=8069)
odoo.login("database", "user", "password")
my_module = odoo.env['my_module.progress_widget_test']
progress_instance = my_module.browse(id)
Every time the progress value changes I call the following method of my module:
progress_instance.updatevalue(new_value)
when the value equals 100 % I close the connection
odoo.logout()
This functionality already exists and you can copy parts of it from account/static/src/js/account_reconciliation_widgets.js from the method updateProgressBar and processReconciliations. You will see here the correct way of updating the progress bar.
The purpose is, that the progressbar should be updated while a process
is running and the user should see the progress without updating the
site.
See on the processReconciliations how it is done, basically you call the process_reconciliations method that exists on the back end and you get a deferred object back. From that deferred object you can use progress()
Looking through the documentation of .progress() you will see that you need to report your progress using .[notify][2]()
How do you define the percentage of completion of your process?

Refresh to repeat control not working normal after deleting 1 row

I have a field named "selectedTime" in a document, this fields stores the selected timings added by user.Adding times is working perfect.This is back-end.
Now I will explain this issue of selecting date from front end.I have given a button add to add times.The custom control of date-time gets added to repeat control on click of Add button.Even if I check in document it shows the list of selected times.Even this works fine.
Now if I want to delete a selected time from repeat control randomly, it deleted that particular record from document, but on the page the last record of the repeat gets disappears,
I was assuming that this is the issue with partial refresh of repeat control,I have even tried that but no result.Full refresh breaks the page.
java script code for the delete button
`var doc:NotesDocument = database.getDocumentByUNID(context.getUrlParameter("refId"))
var selectedTimes:java.util.Vector = doc.getItemValue("selectedTimes");
if(selectedTimes != null){
var sdtString = getComponent("inputHidden1").getValue();
if(selectedTimes.contains(sdtString))
selectedTimes.remove(sdtString);
doc.replaceItemValue("selectedTimes",selectedTimes);
doc.save();
};
var url:XSPUrl = context.getUrl();
view.postScript("window.refresh('"+url+"')");`
I know it is difficult to understand what i want to explain but any suggestion on this will be appreciated.
Even if anybody have any idea to delete the a field values of a documents,In my case field name is "selectedTimes" and the values are added times in repeat control, Please share.
Edit 1:
//Repeat Control
var doc:NotesDocument = database.getDocumentByUNID(context.getUrlParameter("refId"))
var selectedTimes:java.util.Vector = doc.getItemValue("selectedTimes");
return selectedTimes;
Another try could be link the repeat with a viewScope instead of the document:
1) In the event beforeLoadPage/afterLoadPage: Get the value from the document, and put it in a viewScope variable:
// beforeLoadPage event:
// ... get the doc
viewScope.selectedTimes = doc.getItemValue("selectedTimes");
2) In the repeat control, use the viewScope:
<xp:repeat value="#{viewScope.selectedTimes}"...
3) When an update is done, update both the viewScope and the document:
//...update the View Scope variable and get the document:
doc.replaceItemValue("selectedTimes", viewScope.selectedTimes);
This could be a hint if the document would be added as DataSource:
Do you have the document included in the XPage as a DataSource? In that case, try to get and update the NotesXspDocument instead of the Document from the DB:
XPage:
<xp:this.data>
<xp:dominoDocument var="xspDocument"
action="editDocument"
documentId="#{param.unid}">
</xp:dominoDocument>
</xp:this.data>
SSJS code: work directly with the XspDocument
var selectedTimes:java.util.Vector = xspDocument.getItemValue("selectedTimes");
...
xspDocument.replaceItemValue("selectedTimes", selectedTimes);
This could be a hint if the value would not be removed from the document:
In sdtString you are getting a String value:
var sdtString = getComponent("inputHidden1").getValue();
If you have the time values stored as NotesDateTimes, you will get this type of value inside the Vector and the remove method won't find the String and nothing will be removed.
// In a Vector<NotesDateTime> the String cannot be found:
selectedTimes.remove(sdtString);
Be sure you remove the same type of value you get in the Vector

Task "Regarding" field not populating from subgrid in CRM 2013

I am using CRM 2013 on-premise with UR1 installed
I have a custom entity with a subgrid on it looking at related "tasks" which looks like this:
Whenever I create a task from the subgrid using the "+" button in the top right hand corner of the subgrid; the "Regarding" field of the newly created task remains blank. When it should be populated by a lookup to the record it was created from.
I have javascript on the task entity which checks the "Regarding" field to check what kind of entity it was created from (if it was created from one) and gets certain field values from the calling entity to populate fields on the task.
Since the "Regarding" field is never filled the Javascript never fires - and the fields do not populate.
When the record is saved, if the regarding field is blank (I have not manually filled it in) - it will eventually be populated by the correct record about 10 - 15 seconds later if you refresh the page. Then the correct fields will be populated and the user is able to edit the option set values and save again. This is not ideal for the user as they would like it to be one fluid action.
Is there any way around this problem?
EDIT for future browsers of this question:
Found a partial work around. If you use an "Activity" subgrid rather than a "Task" subgrid the field will populate. This has a drawback though as you cannot edit the "Activity" subgrid's view to show "Task" specific fields.
Ran into this same issue. The way I got around it was to add a look-up to the custom entity on the form (we put this on a hidden tab). When the Task gets created from the custom entity the look-up will be populated. You can then use that look-up to grab the values that you need to populate, including the regarding field. Not the most elegant, but it works.
I also ran into this problem and went with a pure JS approach to resolving. On load of the task form, call populateRegarding().
This works because even though the regarding lookup doesn't populate by default, the query string parameters include _CreateFromType and _CreateFromId values.
This works in 2015, didn't test on earlier versions. Note that it is unsupported.
function populateRegarding() {
var regarding = Xrm.Page.getAttribute("regardingobjectid"),
createFromType = Xrm.Page.context.getQueryStringParameters()._CreateFromType,
createFromId = Xrm.Page.context.getQueryStringParameters()._CreateFromId;
if (!createFromId || !createFromType ||
!regarding || regarding.getValue() !== null) {
return;
}
var entityLogicalName = getEntityLogicalNameFromObjectTypeCode(createFromType);
regarding.setValue([{
id: createFromId,
entityType: entityLogicalName,
name: "Hardcoded Name" // TODO: retrieve name dynamically
}]);
}
// This method uses an undocumented object and is therefore unsupported.
// You could implement a supported version of this function by querying for
// metadata, but that would be very expensive.
function getEntityLogicalNameFromObjectTypeCode(otc) {
var map = Mscrm.EntityPropUtil.EntityTypeName2CodeMap,
logicalName;
otc = Number(otc); // convert string to number
for (logicalName in map) {
if (!map.hasOwnProperty(logicalName)) { continue; }
if (map[logicalName] === otc) {
return logicalName;
}
}
}

Categories